我想从一个活动启动IntentService但是没有运行。我尝试过使用toast或Log测试它,但仍然没有给出任何反应。
我出错了吗?
这是我的活动:
public class backgroundApplication extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
findViewById(R.id.cmdServiceIA).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent msgIntent = new Intent(backgroundApplication.this, Service2.class);
startService(msgIntent);
}
});
这是我的intentService:
public class Service extends IntentService{
@Override
protected void onHandleIntent(Intent intent) {
mHandler.post(new DisplayToast(this, "Service Start!"));
}
public class DisplayToast implements Runnable {
private final Context mContext;
String mText;
public DisplayToast(Context mContext, String text){
this.mContext = mContext;
mText = text;
}
public void run(){
Toast.makeText(mContext, mText, Toast.LENGTH_SHORT).show();
}
}
有什么想法吗?