Android : Error showing Toast in intent Service from Alarm Manager

on Sunday, September 14, 2014


Code where I am calling setting alarm



AlarmManager am = ( AlarmManager ) getSystemService( alarm );
Calendar cal = Calendar.getInstance();
// add 5 minutes to the calendar object
cal.add(Calendar.SECOND, 10);

Intent intent = new Intent( "DECREASE_COUNT" );
//intent.setData(Uri.parse("hello"));
PendingIntent pi = PendingIntent.getBroadcast( Activities.this, 0, intent, 0 );

int type = AlarmManager.RTC;


am.set(type, cal.getTimeInMillis(), pi);


My broadcast receiver



public class MyReceiver extends BroadcastReceiver {

@Override
public void onReceive( Context context, Intent intent ) {

Intent myIntent = new Intent( context, MyIntentService.class );
context.startService( myIntent );
}
}

public class MyIntentService extends IntentService {

public MyIntentService(String name) {
super(name);

}

public MyIntentService() {
super("SOME NAME");
}

@Override
protected void onHandleIntent(Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(this, "ServiceCAlled", Toast.LENGTH_LONG).show();
}

}


the error I am getting is,


Handler Sending message to a Handler on a dead thread


What is the cause of this error?


I NEVER see the toast inside my service.


Thanks


0 comments:

Post a Comment