簡體   English   中英

服務意圖。 Android保持崩潰

[英]Service Intent. Android keep crash

我正在學習服務意圖。 但是,它一直崩潰。 發生什么事? 這里有什么問題嗎?

public class SerIntent extends IntentService {

private static final String TAG = "remindme.appsrox.com.intentservice";

public SerIntent() {
    super("SerIntent");
}

@Override
protected void onHandleIntent(Intent intent) {
 Log.i(TAG,"HAHA");
}
}

我也在AndroidManifest.xml中聲明了

<service android:name=".SerIntent" ></service>

這就是主要活動中發生的事情。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Intent i = new Intent(this,SerIntent.class);
    startActivity(i);
}

使用startService(<Intent>)而不是startActivity(<Intent>)來啟動ServiceIntentService

Intent i = new Intent(this,SerIntent.class);
startService(i);

因為startActivity用於啟動Activity。

使用startService()方法:

Intent intent=new Intent("com.sample.service.serviceClass");  
      this.startService(intent);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM