Java Code Examples for android.support.v4.app.ActivityCompat#finishAffinity()

The following examples show how to use android.support.v4.app.ActivityCompat#finishAffinity() . 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
Source File: Navigator.java    From Pioneer with Apache License 2.0 6 votes vote down vote up
/**
     * 回到主界面,可在Splash外的其他界面使用
     * @param activity
     */
    public static void upToMain(Activity activity) {
        Intent intent = new Intent(activity, MainActivity.class);
//        NavUtils.navigateUpTo(activity, intent);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (activity instanceof MainActivity) {
            ((MainActivity) activity).close();
        }
        activity.startActivity(intent);
        activity.overridePendingTransition(0, 0);
        if (!(activity instanceof MainActivity)) {
            ActivityCompat.finishAffinity(activity);
            activity.overridePendingTransition(0, android.R.anim.fade_out);
        }
    }
 
Example 2
Source File: ActivityUtils.java    From Kratos with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 返回上一个Activity
 *
 * @param old     当前Activity的Context
 * @param mBundle
 */
public static void back(Context old, Bundle mBundle, boolean isAffinity) {
    Activity activity = (Activity) old;
    Intent intent = activity.getIntent();
    if (mBundle != null) {
        mBundle.putBoolean(BUNDLE_ACTIVITY_UPDATE, true);
        intent.putExtras(mBundle);
    }
    if (isAffinity) {
        activity.setResult(Activity.RESULT_CANCELED);
        ActivityCompat.finishAffinity(activity);
    } else {
        activity.setResult(Activity.RESULT_OK, intent);
        activity.finish();
    }
}
 
Example 3
Source File: Navigator.java    From Pioneer with Apache License 2.0 6 votes vote down vote up
/**
     * 回到主界面,可在Splash外的其他界面使用
     * @param activity
     */
    public static void upToMain(Activity activity) {
        Intent intent = new Intent(activity, MainActivity.class);
//        NavUtils.navigateUpTo(activity, intent);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (activity instanceof MainActivity) {
            ((MainActivity) activity).close();
        }
        activity.startActivity(intent);
        activity.overridePendingTransition(0, 0);
        if (!(activity instanceof MainActivity)) {
            ActivityCompat.finishAffinity(activity);
            activity.overridePendingTransition(0, android.R.anim.fade_out);
        }
    }
 
Example 4
Source File: LockscreenActivity.java    From AndroidAppLockscreen with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
    super.onBackPressed();
    if (status.equals("check")) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            finishAffinity();
        } else {
            ActivityCompat.finishAffinity(this);
        }
    }
}
 
Example 5
Source File: Navigator.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
/**
     * 启动主界面,可在Splash界面或出现异常时使用.
     * @param context
     */
    public static void launchMain(Context context) {
//        context.getPackageManager().resolveActivity(
//                new Intent(Intent.ACTION_MAIN).setPackage(context.getPackageName())
//                        .addCategory(Intent.CATEGORY_DEFAULT),
//                0);
        boolean inActivityContext = context instanceof Activity;
        Intent intent = new Intent(context, MainActivity.class);
        if (!inActivityContext) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (context instanceof MainActivity) {
            ((MainActivity) context).close();
        }
        context.startActivity(intent);
        if (context instanceof Activity) {
            if (context instanceof SplashActivity)
                ((Activity) context).overridePendingTransition(android.R.anim.fade_in, 0);
            ((Activity) context).overridePendingTransition(0, 0);
        }
        if (context instanceof Activity && !(context instanceof MainActivity)) {
            ActivityCompat.finishAffinity((Activity) context);
            ((Activity) context).overridePendingTransition(0, android.R.anim.fade_out);
        }
    }
 
Example 6
Source File: Navigator.java    From Pioneer with Apache License 2.0 5 votes vote down vote up
/**
     * 启动主界面,可在Splash界面或出现异常时使用.
     * @param context
     */
    public static void launchMain(Context context) {
//        context.getPackageManager().resolveActivity(
//                new Intent(Intent.ACTION_MAIN).setPackage(context.getPackageName())
//                        .addCategory(Intent.CATEGORY_DEFAULT),
//                0);
        boolean inActivityContext = context instanceof Activity;
        Intent intent = new Intent(context, MainActivity.class);
        if (!inActivityContext) {
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (context instanceof MainActivity) {
            ((MainActivity) context).close();
        }
        context.startActivity(intent);
        if (context instanceof Activity) {
            if (context instanceof SplashActivity)
                ((Activity) context).overridePendingTransition(android.R.anim.fade_in, 0);
            ((Activity) context).overridePendingTransition(0, 0);
        }
        if (context instanceof Activity && !(context instanceof MainActivity)) {
            ActivityCompat.finishAffinity((Activity) context);
            ((Activity) context).overridePendingTransition(0, android.R.anim.fade_out);
        }
    }
 
Example 7
Source File: WizardSPUtils.java    From MiPushFramework with GNU General Public License v3.0 4 votes vote down vote up
static void finishWizard (Activity context) {
    setShouldShowWizard(false, context);
    ActivityCompat.finishAffinity(context);
    context.startActivity(new Intent(context,
            MainActivity.class));
}
 
Example 8
Source File: MainActivity.java    From Pioneer with Apache License 2.0 4 votes vote down vote up
public void close() {
    hookFinishToMoveBack = false;
    ActivityCompat.finishAffinity(this);
    overridePendingTransition(0, android.R.anim.fade_out);
}
 
Example 9
Source File: MainActivity.java    From Pioneer with Apache License 2.0 4 votes vote down vote up
public void close() {
    hookFinishToMoveBack = false;
    ActivityCompat.finishAffinity(this);
    overridePendingTransition(0, android.R.anim.fade_out);
}
 
Example 10
Source File: SettingsFragment.java    From fontster with Apache License 2.0 4 votes vote down vote up
private void restartApp() {
  ActivityCompat.finishAffinity(getActivity());
  startActivity(new Intent(getActivity(), MainActivity.class));
}