0
我有一个服务包括电话监听状态,并通过我的application.in版本2.3.3安卓TelephoneManager越来越空的服务
开始时,我退出申请电话经理越来越空,因此手机状态侦听器不起作用以下服务代码任何想法?我在哪里做错了?
当我退出application.but时,服务不会销毁NULL。在setCallListener()方法上设置电话管理器。
我有一个服务来初始化phonestatelistener。服务以两种方式启动:
1-by BOOT_COMPLETED receiver(工作正常的监听程序不为空,并捕获调用)2 - 通过我的应用程序使用startService(new Intent(getApplicationContext(),MyPhoneStateListener.class));
问题是,当服务由我的应用程序启动,然后我的应用程序在这种情况下完成我的听众不工作。我知道TelephoneManager =空值。我该如何提供使应用程序完成后服务意图继续?
public class MyPhoneStateListener extends Service{
SmsBroadcastReceiver _smsbroadcast;
private Context context;
MyCustomStateListener myCustomStateListener;
TelephonyManager telephonymanager;
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId)
{
setCallListener();
_smsbroadcast=new SmsBroadcastReceiver();
GetShieldState();
return START_STICKY;
}
private void setCallListener()
{
try
{
if (telephonymanager==null)
{
telephonymanager = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
myCustomStateListener = new MyCustomStateListener(context,telephonymanager);
telephonymanager.listen(myCustomStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
catch(Exception ex)
{
}
}
@Override
public void onCreate()
{
//Log.e("startservis","create");
context=MyPhoneStateListener.this;
super.onCreate();
}
@Override
public void onDestroy()
{
Log.e("onDestroy","destroy");
}
@Override
public boolean onUnbind(Intent intent)
{
//Toast.makeText(getApplicationContext(),"unbind:", Toast.LENGTH_SHORT).show();
return super.onUnbind(intent);
}
}
我有它。我找到了解决方案。我使用System.exit(0)命令杀死了进程,2.3.3版本服务停止并重新创建,但没有重新启动。所以我的听众是空的。现在我完成改变了System.exit。我也设置了监听器来创建服务的方法。 – user2331641