当前位置: 代码迷 >> Android >> Android 在程序中重新启动APP的方法
  详细解决方案

Android 在程序中重新启动APP的方法

热度:83   发布时间:2016-04-27 23:23:16.0
Android 在程序中重启APP的方法

1. 方法一 利用PackageManager类

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

2. 方法二 利用PendingIntent

Intent mStartActivity = new Intent(context, StartActivity.class);int mPendingIntentId = 123456;PendingIntent mPendingIntent = PendingIntent.getActivity(context, mPendingIntentId,    mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);AlarmManager mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);System.exit(0);

版权声明:本文为博主原创文章,未经博主允许不得转载。

  相关解决方案