You can also use broadcast receiver with PendingIntent to start another activity.
create another class for example receiver as sub class of the BroadcastReceiver
public class receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
// code to start another activity
Intent intent = new Intent(context.getApplicationContext(), MyActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
and define MyActivity as receiver in android menifest file
and in main activity change this code
MyActivity.class to receiver.class
Intent intent = new Intent(this, receiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 34433,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + (5000), pendingIntent);