android 程序崩溃后重启

第一种 
            Intent i = new Intent();
            i.setAction(Intent.ACTION_MAIN);
            i.addCategory(Intent.CATEGORY_LAUNCHER);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            ComponentName cn = new ComponentName(MyApplication.getContext().getPackageName(), LoginActivity.class.getName());
            i.setComponent(cn);
            MyApplication.getContext().startActivity(i);


   
	
第二种	
	Intent intent = new Intent(context, MainActivity.class);
		PendingIntent restartIntent = PendingIntent.getActivity(
				context, 0, intent,
				PendingIntent.FLAG_UPDATE_CURRENT);
		//退出程序
		AlarmManager mgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
		mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
				restartIntent); // 1秒钟后重启应用
		android.os.Process.killProcess(android.os.Process.myPid());

你可能感兴趣的:(bug,android,AndroidBUGFix)