public static Intent makeRestartActivityTask(ComponentName mainActivity) { return Intent.makeRestartActivityTask(mainActivity); } }
public void nextActivity(Class<?> firstCls, Class<?> SecondCls) { Intent[] intents = new Intent[2]; intents[0] = Intent.makeRestartActivityTask(new ComponentName(this, SecondCls)); intents[1] = new Intent(this, firstCls); startActivities(intents); }
/** * This creates an array of Intent objects representing the back stack * for a user going into the Views/Lists API demos. */ private Intent[] buildIntentsToViewsLists() { // We are going to rebuild our task with a new back stack. This will // be done by launching an array of Intents, representing the new // back stack to be created, with the first entry holding the root // and requesting to reset the back stack. Intent[] intents = new Intent[3]; // First: root activity of ApiDemos. // This is a convenient way to make the proper Intent to launch and // reset an application's task. intents[0] = Intent.makeRestartActivityTask(new ComponentName(this, com.example.android.apis.ApiDemos.class)); Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClass(IntentActivityFlags.this, com.example.android.apis.ApiDemos.class); intent.putExtra("com.example.android.apis.Path", "Views"); intents[1] = intent; intent = new Intent(Intent.ACTION_MAIN); intent.setClass(IntentActivityFlags.this, com.example.android.apis.ApiDemos.class); intent.putExtra("com.example.android.apis.Path", "Views/Lists"); intents[2] = intent; return intents; }
intents[0] = Intent.makeRestartActivityTask(new ComponentName(context, com.example.android.apis.ApiDemos.class));
/** * This method creates an array of Intent objects representing the * activity stack for the incoming message details state that the * application should be in when launching it from a notification. */ static Intent[] makeMessageIntentStack(Context context, CharSequence from, CharSequence msg) { // A typical convention for notifications is to launch the user deeply // into an application representing the data in the notification; to // accomplish this, we can build an array of intents to insert the back // stack stack history above the item being displayed. Intent[] intents = new Intent[4]; // First: root activity of ApiDemos. // This is a convenient way to make the proper Intent to launch and // reset an application's task. intents[0] = Intent.makeRestartActivityTask(new ComponentName(context, com.example.android.apis.ApiDemos.class)); // "App" intents[1] = new Intent(context, com.example.android.apis.ApiDemos.class); intents[1].putExtra("com.example.android.apis.Path", "App"); // "App/Notification" intents[2] = new Intent(context, com.example.android.apis.ApiDemos.class); intents[2].putExtra("com.example.android.apis.Path", "App/Notification"); // Now the activity to display to the user. Also fill in the data it // should display. intents[3] = new Intent(context, IncomingMessageView.class); intents[3].putExtra(IncomingMessageView.KEY_FROM, from); intents[3].putExtra(IncomingMessageView.KEY_MESSAGE, msg); return intents; }
intents[0] = Intent.makeRestartActivityTask(new ComponentName(this, com.example.android.apis.ApiDemos.class));
private PendingIntent makeDefaultIntent() { // A typical convention for notifications is to launch the user deeply // into an application representing the data in the notification; to // accomplish this, we can build an array of intents to insert the back // stack stack history above the item being displayed. Intent[] intents = new Intent[4]; // First: root activity of ApiDemos. // This is a convenient way to make the proper Intent to launch and // reset an application's task. intents[0] = Intent.makeRestartActivityTask(new ComponentName(this, com.example.android.apis.ApiDemos.class)); // "App" intents[1] = new Intent(this, com.example.android.apis.ApiDemos.class); intents[1].putExtra("com.example.android.apis.Path", "App"); // "App/Notification" intents[2] = new Intent(this, com.example.android.apis.ApiDemos.class); intents[2].putExtra("com.example.android.apis.Path", "App/Notification"); // Now the activity to display to the user. intents[3] = new Intent(this, StatusBarNotifications.class); // The PendingIntent to launch our activity if the user selects this // notification. Note the use of FLAG_UPDATE_CURRENT so that if there // is already an active matching pending intent, we will update its // extras (and other Intents in the array) to be the ones passed in here. PendingIntent contentIntent = PendingIntent.getActivities(this, 0, intents, PendingIntent.FLAG_UPDATE_CURRENT); return contentIntent; }
intents[0] = Intent.makeRestartActivityTask(new ComponentName(this, com.example.android.apis.ApiDemos.class));
private static Intent makeRestartActivityTaskGuarded(ComponentName cn) throws InvocationException { try { return Intent.makeRestartActivityTask(cn); } catch (NoSuchMethodError e) { //return IntentCompat.makeRestartActivityTask(cn); Invocation invocation = Invocation.fromClass(IntentCompat.class); return (Intent) invocation.invokeMethod("makeRestartActivityTask", new Class<?>[]{ComponentName.class}, new Object[]{cn}); } }
public static void doRestart(@NonNull Context context) { try { PackageManager pm = context.getPackageManager(); if (pm != null) { Intent intent = pm.getLaunchIntentForPackage(context.getPackageName()); if (intent != null) { ComponentName componentName = intent.getComponent(); Intent mainIntent = Intent.makeRestartActivityTask(componentName); mainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); context.startActivity(mainIntent); Runtime.getRuntime().exit(0); } else { Timber.d("Was not able to restart application, intent null"); } } else { Timber.d("Was not able to restart application, PM null"); } } catch (Exception e) { Timber.e(e, "Was not able to restart application"); } }