Hi, I would like to restart my application after the user set his/her preferences (restart() method of my MyApplication class will be invoked). I am using an AlarmManager to start my application right after I kill it. I have no idea why my BroadcastReceiver is never called. Anyone can advise on how I can resolve this? Thanks.
public void restart() {
// Setup one-short alarm to restart my application in 3 seconds
AlarmManager alarmMgr=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent i=new Intent(context, RestartProcessor.class);
PendingIntent pi=PendingIntent.getBroadcast(context, 0, i, 0);
alarmMgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+3000, pi);
// Kill my application
ActivityManager actmgr=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
actmgr.restartPackage("com.MyApplication");
}
public class RestartProcessor extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
ActivityManager actmgr=(ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);
try {
Intent i = new Intent(context, MyApplication.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startService(i);
} catch (Exception e) {}
}
}


