[英]Service stops in android version Oreo and app crashes
服务在android版本Oreo中停止,并且应用程序崩溃。 请大家帮我解决这个问题。 当我尝试添加startServiceForeground()
,它崩溃了,我不知道发生了什么,所以请帮助我。
//Start Service method
private void startSipService() {
Thread t = new Thread("StartSip") {
public void run() {
Intent serviceIntent = new Intent(SipHome.this,SipService.class);
serviceIntent.putExtra(SipManager.EXTRA_OUTGOING_ACTIVITY,
new ComponentName(SipHome.this, SipHome.class));
startService(serviceIntent);z
if(user==null||user==""){
postStartSipService();
}
// boolean status;
// status = loginStatus();
// if (!status){}
// postStartSipService();
}
};
t.start();
}
尝试这个:
Intent myService = new Intent(this, MyService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(myService);
} else {
startService(myService);
}
Android 8.0(API级别26)还包括对特定方法的以下更改:如果针对Android 8.0的应用尝试在不允许创建后台服务的情况下尝试使用该方法,则startService()
方法现在将引发IllegalStateException
。
新的Context.startForegroundService()
方法启动前台服务。 该系统允许应用程序在后台运行时调用Context.startForegroundService()
。 但是,应用程序必须在创建服务后五秒钟内调用该服务的startForeground()
方法。 有关更多信息,请参见后台执行限制 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.