0
如果強制停止,我試圖在接收短信時重新啓動我的應用程序。這是我的代碼。 它不重新啓動應用程序。我應該嘗試將接收器作爲另一個類編寫。 在清單:重新啓動力在收到短信時停止了應用程序
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<receiver android:name=".MySMSbr">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
My mainActivity onCreate() :
private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
BroadcastReceiver SMSbr;
public void onCreate(Bundle savedInstanceState) {
Toast.makeText(getApplicationContext(),"in OnCreate", Toast.LENGTH_LONG).show();
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SMSbr = new BroadcastReceiver()
{
@Override
public void onReceive(Context context,Intent intent)
{
this.abortBroadcast();
Toast.makeText(context, "in onReceive", Toast.LENGTH_LONG).show();
toggleLogging(AppSettings.getServiceRunning(MainActivity.this),
AppSettings.getLoggingInterval(MainActivity.this));
this.clearAbortBroadcast();
}//end of onReceive method
};//end of BroadcastReceiver
IntentFilter SMSfilter = new IntentFilter(SMS_RECEIVED);
this.registerReceiver(SMSbr, SMSfilter);
}
in togglelogging the service is started
where is it going wrong.
據我所知,力停止的應用程序不能用'Intent'在Android 3.x和較新的 – 2013-04-08 11:38:14
我該怎麼辦,然後 – Manasi 2013-04-08 11:39:19
服務在另一個進程開始應在這種情況下仍然存活 – 2013-04-08 12:06:00