我正面临一些我根本不理解的事情,这可能来自我对Android非常陌生的事实。Android:应用程序重新启动后服务未启动
我启动了一个创建服务的简单活动。这里没有魔法。一切正常,当我启动应用程序。但是如果我杀了它并在几秒钟内再次启动它,我的服务不会启动(我在我的服务的OnCreate()方法上添加了一个日志,并且没有显示任何内容)。
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Log.d(TAG, "ON CREATE");
s_instance = this;
registerReceiver(deviceEventReceiver, new IntentFilter("com.horizon.watch.moto360.receiveDeviceEvent"));
setContentView(R.layout.activity_main);
//Launch default home page
defaultHomePage = (FrameLayout) findViewById(R.id.defaulthomepage);
defaultHomePage.setVisibility(View.VISIBLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
startService(new Intent(this, WearMessageListenerService.class));
}
@Override
protected void onDestroy() {
Log.d(TAG, "ON DESTROY");
stopService(new Intent(this, WearMessageListenerService.class));
unregisterReceiver(deviceEventReceiver);
super.onDestroy();
}
是您的服务清单文件中列出? – bubunyo
是的。这很奇怪,就像我没有及时销毁服务,并且在我重新启动应用程序时不能重新创建 – krakig
如果服务正在运行,则开始对服务进行检查 – bubunyo