Android 为什么应用程序关闭时服务重新启动
我有一个简单的带有数据的服务-ArrayListAndroid 为什么应用程序关闭时服务重新启动,android,service,Android,Service,我有一个简单的带有数据的服务-ArrayList,当我关闭应用程序时-服务被重新启动,称为onCreate方法,数据正在丢失。这是我的onStartCommand方法: public int onStartCommand(Intent intent, int flags, int startId) { ..... return START_STICKY; } 应用程序类中的服务启动 Intent serviceIntent = new Intent(this, ChatNo
public int onStartCommand(Intent intent, int flags, int startId) {
.....
return START_STICKY;
}
应用程序类中的服务启动
Intent serviceIntent = new Intent(this, ChatNotificationService.class);
startService(serviceIntent);
我没有调用stopService方法
我需要在关闭应用程序后,服务继续工作,数据保存在其中。
我怎么能做到
在活动中:
@Override
protected void onCreate() {
super.onCreate();
bindService(serviceIntent, sConn, 0);
}
@Override
public void onDestroy(){
super.onDestroy();
chatNotificationService.closeConnections();
unbindService(sConn);
}
请发布活动的onCreate、onStart、onPause和onStop方法。您阅读了吗?是的,它对我不起作用。显然,在方法onCreate中保存和检索它们的唯一方法。