Java Code Examples for android.app.Activity#finish()
The following examples show how to use
android.app.Activity#finish() .
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: PreferencesActivity.java From PowerFileExplorer with GNU General Public License v3.0 | 6 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // Navigate "up" the demo structure to the launchpad activity. if (selectedItem != START_PREFERENCE && changed) restartPC(this); else if (selectedItem != START_PREFERENCE) { selectItem(START_PREFERENCE); } else { Intent in = new Intent(PreferencesActivity.this, ExplorerActivity.class); in.setAction(Intent.ACTION_MAIN); in.setAction(Intent.CATEGORY_LAUNCHER); final int enter_anim = android.R.anim.fade_in; final int exit_anim = android.R.anim.fade_out; Activity activity = this; activity.overridePendingTransition(enter_anim, exit_anim); activity.finish(); activity.overridePendingTransition(enter_anim, exit_anim); activity.startActivity(in); } return true; } return true; }
Example 2
Source File: LoginUtil.java From smart-farmer-android with Apache License 2.0 | 6 votes |
static void action(Activity activity) { switch (mPlatform) { case LoginPlatform.QQ: mLoginInstance = new QQLoginInstance(activity, mLoginListener, isFetchUserInfo); break; case LoginPlatform.WEIBO: mLoginInstance = new WeiboLoginInstance(activity, mLoginListener, isFetchUserInfo); break; case LoginPlatform.WX: mLoginInstance = new WxLoginInstance(activity, mLoginListener, isFetchUserInfo); break; default: mLoginListener.loginFailure(new Exception(INFO.UNKNOW_PLATFORM)); activity.finish(); } mLoginInstance.doLogin(activity, mLoginListener, isFetchUserInfo); }
Example 3
Source File: ChromeLifetimeController.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override public void onTerminate(boolean restart) { mRestartChromeOnDestroy = restart; for (WeakReference<Activity> weakActivity : ApplicationStatus.getRunningActivities()) { Activity activity = weakActivity.get(); if (activity != null) { ApplicationStatus.registerStateListenerForActivity(this, activity); mRemainingActivitiesCount++; activity.finish(); } } // Start the Activity that will ultimately kill this process. fireBrowserRestartActivityIntent(BrowserRestartActivity.ACTION_START_WATCHDOG); }
Example 4
Source File: MonitoringInstrumentation.java From android-test with Apache License 2.0 | 6 votes |
@Override public void run() { List<Activity> activities = new ArrayList<>(); for (Stage s : EnumSet.range(Stage.CREATED, Stage.STOPPED)) { activities.addAll(lifecycleMonitor.getActivitiesInStage(s)); } if (activities.size() > 0) { Log.i(TAG, "Activities that are still in CREATED to STOPPED: " + activities.size()); } for (Activity activity : activities) { if (!activity.isFinishing()) { try { Log.i(TAG, "Finishing activity: " + activity); activity.finish(); } catch (RuntimeException e) { Log.e(TAG, "Failed to finish activity.", e); } } } }
Example 5
Source File: BundleLauncher.java From Small with Apache License 2.0 | 6 votes |
/** * Called after {@link #prelaunchBundle(Bundle)}. * * This is usually starting an activity. * * @param bundle the launching bundle * @param context current context */ public void launchBundle(Bundle bundle, Context context) { if (!bundle.isLaunchable()) { // TODO: Exit app return; } if (context instanceof Activity) { Activity activity = (Activity) context; if (shouldFinishPreviousActivity(activity)) { activity.finish(); } activity.startActivityForResult(bundle.getIntent(), Small.REQUEST_CODE_DEFAULT); } else { context.startActivity(bundle.getIntent()); } }
Example 6
Source File: AndroidLifecycleBridge.java From CrossMobile with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void quit(final String error, final Throwable throwable) { if (isQuitting) return; isQuitting = true; super.quit(error, throwable); for (WeakReference<Activity> item : activitylist) try { Activity activity = item.get(); if (activity != null) activity.finish(); } catch (Exception ignored) { } activitylist.clear(); MainActivity c = MainActivity.current; if (c != null) { if (error != null) Native.system().postOnEventThread(() -> Toast.makeText(c, error, Toast.LENGTH_LONG).show()); c.finish(); } }
Example 7
Source File: AppManager.java From FamilyChat with Apache License 2.0 | 5 votes |
/** * finish一个Activity并将其从栈中移除 * * @param activity 待移除实例 * @return 移除成功/失败 */ public boolean finishActivity(Activity activity) { if (activity != null && !activity.isFinishing()) { activity.finish(); if (mStackList != null) return mStackList.remove(activity); else return false; } else { return false; } }
Example 8
Source File: CreateShotFragment.java From droidddle with Apache License 2.0 | 5 votes |
private void shotUpdated(Shot shot) { Activity activity = getActivity(); if (activity == null) { return; } UiUtils.dismissDialog(mDialog); UiUtils.showToast(activity, R.string.shot_updated); activity.setResult(Activity.RESULT_OK); activity.finish(); }
Example 9
Source File: UIHelper.java From qingyang with Apache License 2.0 | 5 votes |
/** * 点击返回监听事件 * * @param activity * @return */ public static View.OnClickListener finish(final Activity activity) { return new View.OnClickListener() { public void onClick(View v) { activity.finish(); } }; }
Example 10
Source File: CustomExceptions.java From faceswap with Apache License 2.0 | 5 votes |
public static void notifyError(String msg, final boolean terminate, final Activity activity){ DialogInterface.OnClickListener error_listener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (terminate){ activity.finish(); } } }; new AlertDialog.Builder(activity) .setTitle("Error").setMessage(msg) .setNegativeButton("close", error_listener).show(); }
Example 11
Source File: GoHomeClickListener.java From YiBo with Apache License 2.0 | 5 votes |
@Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction(Constants.ACTION_WEIBO_MAIN); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Activity context = (Activity)v.getContext(); context.startActivity(intent); context.finish(); }
Example 12
Source File: AppManager.java From FriendBook with GNU General Public License v3.0 | 5 votes |
/** * 结束所有Activity */ public void finishAllActivity() { Iterator<Activity> iterator = mActivityStack.iterator(); while (iterator.hasNext()) { Activity activity = iterator.next(); iterator.remove(); activity.finish(); } }
Example 13
Source File: AppManager.java From MVVMArms with Apache License 2.0 | 5 votes |
/** * 关闭指定的 activity class 的所有的实例 * * @param activityClass activity class */ public void killActivity(Class<?> activityClass) { if (mActivityList == null) { Timber.tag(TAG).w("mActivityList == null when killActivity(Class)"); return; } for (Activity activity : mActivityList) { if (activity.getClass().equals(activityClass)) { activity.finish(); } } }
Example 14
Source File: CameraTest.java From Camera2 with Apache License 2.0 | 5 votes |
private void checkActivityLeak(String action) throws Exception { final int TEST_COUNT = 5; Intent intent = new Intent(action); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setClass(getInstrumentation().getTargetContext(), CameraActivity.class); ArrayList<WeakReference<Activity>> refs = new ArrayList<WeakReference<Activity>>(); for (int i = 0; i < TEST_COUNT; i++) { Activity activity = getInstrumentation().startActivitySync(intent); refs.add(new WeakReference<Activity>(activity)); activity.finish(); getInstrumentation().waitForIdleSync(); activity = null; } Runtime.getRuntime().gc(); Runtime.getRuntime().runFinalization(); Runtime.getRuntime().gc(); int refCount = 0; for (WeakReference<Activity> c : refs) { if (c.get() != null) { refCount++; } } // If applications are leaking activity, every reference is reachable. assertTrue(refCount != TEST_COUNT); }
Example 15
Source File: ActivityCompat.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * 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 {@link Activity#finish()} will be called instead.</p> */ public static void finishAffinity(Activity activity) { if (Build.VERSION.SDK_INT >= 16) { ActivityCompatJB.finishAffinity(activity); } else { activity.finish(); } }
Example 16
Source File: FileUtils.java From keemob with MIT License | 4 votes |
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.filesystems = new ArrayList<Filesystem>(); this.pendingRequests = new PendingRequests(); String tempRoot = null; String persistentRoot = null; Activity activity = cordova.getActivity(); String packageName = activity.getPackageName(); String location = preferences.getString("androidpersistentfilelocation", "internal"); tempRoot = activity.getCacheDir().getAbsolutePath(); if ("internal".equalsIgnoreCase(location)) { persistentRoot = activity.getFilesDir().getAbsolutePath() + "/files/"; this.configured = true; } else if ("compatibility".equalsIgnoreCase(location)) { /* * Fall-back to compatibility mode -- this is the logic implemented in * earlier versions of this plugin, and should be maintained here so * that apps which were originally deployed with older versions of the * plugin can continue to provide access to files stored under those * versions. */ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { persistentRoot = Environment.getExternalStorageDirectory().getAbsolutePath(); tempRoot = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + packageName + "/cache/"; } else { persistentRoot = "/data/data/" + packageName; } this.configured = true; } if (this.configured) { // Create the directories if they don't exist. File tmpRootFile = new File(tempRoot); File persistentRootFile = new File(persistentRoot); tmpRootFile.mkdirs(); persistentRootFile.mkdirs(); // Register initial filesystems // Note: The temporary and persistent filesystems need to be the first two // registered, so that they will match window.TEMPORARY and window.PERSISTENT, // per spec. this.registerFilesystem(new LocalFilesystem("temporary", webView.getContext(), webView.getResourceApi(), tmpRootFile)); this.registerFilesystem(new LocalFilesystem("persistent", webView.getContext(), webView.getResourceApi(), persistentRootFile)); this.registerFilesystem(new ContentFilesystem(webView.getContext(), webView.getResourceApi())); this.registerFilesystem(new AssetFilesystem(webView.getContext().getAssets(), webView.getResourceApi())); registerExtraFileSystems(getExtraFileSystemsPreference(activity), getAvailableFileSystems(activity)); // Initialize static plugin reference for deprecated getEntry method if (filePlugin == null) { FileUtils.filePlugin = this; } } else { LOG.e(LOG_TAG, "File plugin configuration error: Please set AndroidPersistentFileLocation in config.xml to one of \"internal\" (for new applications) or \"compatibility\" (for compatibility with previous versions)"); activity.finish(); } }
Example 17
Source File: NavUtils.java From V.FlyoutTest with MIT License | 4 votes |
@Override public void navigateUpTo(Activity activity, Intent upIntent) { upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); activity.startActivity(upIntent); activity.finish(); }
Example 18
Source File: ExitApplication.java From MortgageCalculator with Apache License 2.0 | 4 votes |
public void exit(){ for (Activity activity : activityList){ activity.finish(); } System.exit(0); }
Example 19
Source File: TvApiEventListener.java From jellyfin-androidtv with GNU General Public License v2.0 | 4 votes |
@Override public void onPlaystateCommand(ApiClient client, PlaystateRequest command) { PlaybackController playbackController = TvApp.getApplication().getPlaybackController(); switch (command.getCommand()) { case Stop: if (MediaManager.isPlayingAudio()) MediaManager.stopAudio(); else { Activity currentActivity = TvApp.getApplication().getCurrentActivity(); if(currentActivity instanceof PlaybackOverlayActivity) currentActivity.finish(); } break; case Pause: if (MediaManager.isPlayingAudio()) MediaManager.pauseAudio(); else if(playbackController != null) playbackController.playPause(); break; case Unpause: if (MediaManager.hasAudioQueueItems()) MediaManager.resumeAudio(); else if(playbackController != null) playbackController.playPause(); break; case NextTrack: if (MediaManager.hasAudioQueueItems()) MediaManager.nextAudioItem(); else if(playbackController != null) playbackController.next(); break; case PreviousTrack: if (MediaManager.hasAudioQueueItems()) MediaManager.prevAudioItem(); else if(playbackController != null) playbackController.prev(); break; case Seek: if (playbackController == null) break; long pos = command.getSeekPositionTicks() / 10000; playbackController.seek(pos); break; case Rewind: if (playbackController == null) break; playbackController.skip(-11000); break; case FastForward: if (playbackController == null) break; playbackController.skip(30000); break; } }
Example 20
Source File: CustomActivityOnCrash.java From AndroidWallet with GNU General Public License v3.0 | 3 votes |
/** * Closes the app. * If an event listener is provided, the close app event is invoked. * Must only be used from your error activity. * * @param activity The current error activity. Must not be null. * @param config The config object as obtained by calling getConfigFromIntent. */ public static void closeApplication(@NonNull Activity activity, @NonNull CaocConfig config) { if (config.getEventListener() != null) { config.getEventListener().onCloseAppFromErrorActivity(); } activity.finish(); killCurrentProcess(); }