[英]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.