Java Code Examples for android.app.Activity#finishAffinity()

The following examples show how to use android.app.Activity#finishAffinity() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void onPermissionDenied() {
    Activity activity = (Activity)ContextMgr.getContext();
    if(activity != null){
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            activity.finishAffinity();
        }else{
            activity.finish();
        }
    }

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            Process.killProcess(Process.myPid());
        }
    }, 200);
}
 
Example 2
@Override
protected void onPostExecute(Void result) {
    Activity activity = activityWeakReference.get();
    if (activity!=null) {
        activity.finishAffinity();
        if (destAccount==null) {
            Intent intent = new Intent(activity, WelcomeActivity.class);
            if (qrAccount!=null) {
                intent.putExtra(WelcomeActivity.QR_ACCOUNT_EXTRA, qrAccount);
            }
            activity.startActivity(intent);
        } else {
            activity.startActivity(new Intent(activity.getApplicationContext(), ConversationListActivity.class));
        }
    }
}
 
Example 3
/**
 * Finish this activity, and tries to finish all activities immediately below it in the current
 * task that have the same affinity.
 *
 * <p>On Android 4.1+ calling this method will call through to the native version of this method.
 * For other platforms will {@link Activity#setResult(int)} with @param resultCode and immediatly
 * after {@link Activity#finish()} will be called instead.
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static void finishAffinity(Activity activity, int resultCode) {
  if (activity == null) {
    return;
  }
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    activity.finishAffinity();
  } else {
    activity.setResult(resultCode);
    activity.finish();
  }
}
 
Example 4
Source Project: letv   File: CommonUtils.java    License: Apache License 2.0 5 votes vote down vote up
@TargetApi(16)
public static void finishAffinity(Activity activity, int resultCode) {
    if (activity != null) {
        if (VERSION.SDK_INT >= 16) {
            activity.finishAffinity();
            return;
        }
        activity.setResult(resultCode);
        activity.finish();
    }
}
 
Example 5
/**
 * restart application
 *
 * <p>
 * Stop all active activities and launch application again with default launch intent.
 * Start activity from background without permission is not allowed since Android Q,
 * AlarmManager method won't work without grant permission
 * </p>
 * @param activity activity instance
 */
public static void restartApplication(Activity activity) {
    if (activity != null) {
        activity.finishAffinity();
    }
    String packageName = ContextProvider.get().getPackageName();
    Intent mStartActivity = ContextProvider.get().getPackageManager().getLaunchIntentForPackage(packageName);
    if (mStartActivity == null) {
        return;
    }
    mStartActivity.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    mStartActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ContextProvider.get().startActivity(mStartActivity);
}
 
Example 6
Source Project: island   File: IslandSetup.java    License: Apache License 2.0 5 votes vote down vote up
private static void deactivateDeviceOwner(final Activity activity) {
	Analytics.$().event("action_deactivate").send();
	final DevicePolicies policies = new DevicePolicies(activity);
	policies.getManager().clearDeviceOwnerApp(activity.getPackageName());
	try {	// Since Android 7.1, clearDeviceOwnerApp() itself does remove active device-admin,
		policies.execute(DevicePolicyManager::removeActiveAdmin);
	} catch (final SecurityException ignored) {}		//   thus SecurityException will be thrown here.

	activity.finishAffinity();	// Finish the whole activity stack.
	System.exit(0);		// Force termination of the whole app, to avoid potential inconsistency.
}
 
Example 7
Source Project: MiBandDecompiled   File: i.java    License: Apache License 2.0 4 votes vote down vote up
public static void a(Activity activity)
{
    activity.finishAffinity();
}
 
Example 8
public static void finishAffinity(Activity activity) {
    activity.finishAffinity();
}
 
Example 9
public static void finishAffinity(Activity activity) {
    activity.finishAffinity();
}
 
Example 10
Source Project: V.FlyoutTest   File: ActivityCompatJB.java    License: MIT License 4 votes vote down vote up
public static void finishAffinity(Activity activity) {
    activity.finishAffinity();
}
 
Example 11
Source Project: guideshow   File: ActivityCompatJB.java    License: MIT License 4 votes vote down vote up
public static void finishAffinity(Activity activity) {
    activity.finishAffinity();
}
 
Example 12
/**
 * close application
 * <p>
 * Stop all active activities and call Runtime.exit() after 500ms
 * </p>
 * @param activity activity instance
 */
public static void exitApplication(Activity activity) {
    if (activity != null) {
        activity.finishAffinity();
    }
    new Handler().postDelayed(() -> Runtime.getRuntime().exit(0), 500);
}
 
Example 13
Source Project: Bop   File: Main.java    License: Apache License 2.0 1 votes vote down vote up
/**
 * Forces the whole application to quit.
 * <p>
 * Please read more info on this StackOverflow answer:
 * http://stackoverflow.com/a/4737595
 *
 * @note This is dangerous, make sure to cleanup
 * everything before calling this.
 */
public static void forceExit(Activity c) {

    c.finish();
    c.finishAffinity();

}