How to start a different activity with some delay after pressing a button in android?

后端 未结 7 724
感动是毒
感动是毒 2020-12-30 04:14

I want that a new activity should start with some delay on pressing a button. Is it possible to do that , and whats the procedure.

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 04:31

    Sometimes, u need to do it whenever your app process is killed or not. In that case you can not use handling runnable or messages inside your process. In this case your can just use AlarmManager to this. Hope this example helps anybody:

    Intent intent = new Intent();
    ...
    
    PendingIntent pendingIntent = PendingIntent.getActivity(, 0, intent, PendingIntent.FLAG_ONE_SHOT);
    AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    mgr.set(AlarmManager.RTC, , pendingIntent);
    

提交回复
热议问题