首页 > 移动平台 > 详细

android 业务需求: 先干掉自己, 在重启自己

时间:2014-03-19 16:43:52      阅读:519      评论:0      收藏:0      [点我收藏+]
1
2
3
4
5
6
7
8
9
10
11
12
13
// 重启应用
public void restartApp() {
    Intent intent = new Intent();
    // 参数1:包名,参数2:程序入口的activity
    intent.setClassName(getPackageName(), "包名");
    PendingIntent restartIntent = PendingIntent.getActivity(
            getApplicationContext(), 0, intent,
            Intent.FLAG_ACTIVITY_NEW_TASK);
    AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
            restartIntent); // 1秒钟后重启应用
    finishProgram(); // 自定义方法,关闭当前打开的所有avtivity
}

 2:第二种方式:

1
2
3
Intent i = getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());   i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

  

android 业务需求: 先干掉自己, 在重启自己,布布扣,bubuko.com

android 业务需求: 先干掉自己, 在重启自己

原文:http://www.cnblogs.com/porter/p/3611559.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!