[英]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>)
來啟動Service
或IntentService
:
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.