List of usage examples for android.app Activity finish
public void finish()
From source file:Main.java
public static boolean startLastActivity(Activity activity) { try {//from w ww .jav a2 s .c o m BufferedReader reader = new BufferedReader(new InputStreamReader(activity.openFileInput(FILENAME))); String nextClassName = reader.readLine(); reader.close(); if (null == nextClassName || nextClassName.length() < 3) { return false; } String currClassName = activity.getClass().getName(); if (currClassName.equals(nextClassName)) { return false; } @SuppressWarnings("unchecked") Class<? extends Activity> clazz = (Class<? extends Activity>) Class.forName(nextClassName); if (null == clazz) { return false; } Intent i = new Intent(activity, clazz); activity.startActivity(i); activity.finish(); reader.close(); return true; } catch (Exception e) { Toast.makeText(activity, "startLastActivity: " + e, Toast.LENGTH_LONG).show(); } return false; }
From source file:io.digibyte.tools.animation.BRAnimator.java
public static void startBreadActivity(Activity from, boolean auth) { if (from == null) return;//from ww w .j ava2 s.c om Log.e(TAG, "startBreadActivity: " + from.getClass().getName()); Class toStart = auth ? LoginActivity.class : BreadActivity.class; Intent intent = new Intent(from, toStart); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); from.startActivity(intent); from.overridePendingTransition(R.anim.fade_up, R.anim.fade_down); if (!from.isDestroyed()) { from.finish(); } }
From source file:org.symptomcheck.capstone.utils.NotificationHelper.java
/** * Convenient method to build and show an Alert dialog * @param context Context used to build alert dialog * @param alertType type of alert/*from w ww . j a v a2 s.co m*/ * @param Title Title of alert * @param Message Message to be shown in the body alert */ public static void showAlertDialog(final Activity context, AlertType alertType, String Title, String Message) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); // set title alertDialogBuilder.setTitle(Title); switch (alertType) { case ALERT_GO_TO_LOGIN: // set dialog message alertDialogBuilder.setMessage("You aren't logged. Do you want re-enter credential?") .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity context.finish(); Intent intent = new Intent(context, LoginActivity.class); intent.putExtra(NEXT_ACTIVITY_TO_LAUNCH, GO_TO_CHECK_IN); context.startActivity(intent); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); context.finish(); } }); break; case ALERT_CHECK_IN_CONFIRMATION: // set dialog message alertDialogBuilder.setMessage(Message).setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close // current activity dialog.cancel(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // if this button is clicked, just close // the dialog box and do nothing dialog.cancel(); } }); break; } // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); }
From source file:com.google.android.libraries.cast.companionlibrary.utils.Utils.java
/** * A utility method to validate that the appropriate version of the Google Play Services is * available on the device. If not, it will open a dialog to address the issue. The dialog * displays a localized message about the error and upon user confirmation (by tapping on * dialog) will direct them to the Play Store if Google Play services is out of date or * missing, or to system settings if Google Play services is disabled on the device. *//* www . ja v a2 s . c om*/ public static boolean checkGooglePlayServices(final Activity activity) { final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity); switch (googlePlayServicesCheck) { case ConnectionResult.SUCCESS: return true; default: Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { activity.finish(); } }); dialog.show(); } return false; }
From source file:com.mediatek.contacts.activities.ActivitiesUtils.java
/** For CR ALPS01541210 */ public static boolean checkContactsProcessIsBusy(final Activity activity) { // Since busy return directly no receiver is registered boolean isProcessBusy = ContactsApplicationEx.isContactsApplicationBusy(); Log.d(TAG, "[checkContactsProcessIsBusy]isProcessBusy = " + isProcessBusy); if (isProcessBusy) { activity.runOnUiThread(new Runnable() { @Override/*w ww . j a v a2 s . c o m*/ public void run() { MtkToast.toast(activity.getApplicationContext(), R.string.phone_book_busy); } }); activity.finish(); return true; } return false; }
From source file:de.wikilab.android.friendica01.Max.java
/** * displays the login form (layout/loginscreen.xml) as a modal dialog and calls tryLogin * when user confirms the form//from w w w . j a v a2 s . c o m * @param ctx MUST IMPLEMENT LoginListener !!! * @param errmes message which is displayed above the Login form (e.g. "wrong password entered") */ public static void showLoginForm(final Activity ctx, String errmes) { Log.v(TAG, "... showLoginForm"); View myView = ctx.getLayoutInflater().inflate(R.layout.loginscreen, null, false); final AlertDialog alert = new AlertDialog.Builder(ctx).setTitle("Login to Friendica").setView(myView) .setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { ctx.finish(); } }).show(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); String protocol = prefs.getString("login_protocol", "https"); String server = prefs.getString("login_server", null); String userName = prefs.getString("login_user", null); if (errmes != null) { ((TextView) myView.findViewById(R.id.lblInfo)).setText(errmes); } final Spinner selProtocol = (Spinner) myView.findViewById(R.id.selProtocol); selProtocol.setSelection(protocol.equals("https") ? 1 : 0); //HACK !!! final EditText edtServer = (EditText) myView.findViewById(R.id.edtServer); edtServer.setText(server); final EditText edtUser = (EditText) myView.findViewById(R.id.edtUser); edtUser.setText(userName); final EditText edtPassword = (EditText) myView.findViewById(R.id.edtPassword); ((TextView) myView.findViewById(R.id.proxy_settings)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ctx.startActivity(new Intent(ctx, PreferencesActivity.class)); } }); ((Button) myView.findViewById(R.id.button1)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(ctx).edit(); prefs.putString("login_protocol", selProtocol.getSelectedItem().toString()); String server = edtServer.getText().toString(); server = server.replaceAll("^https?://", ""); prefs.putString("login_server", server); prefs.putString("login_user", edtUser.getText().toString()); prefs.putString("login_password", edtPassword.getText().toString()); prefs.commit(); alert.dismiss(); tryLogin(ctx); } }); }
From source file:org.cinedroid.util.CineworldAPIAssistant.java
/** * Create a dialog with the text "Problem connecting to the Cineworld API", with two buttons, "Retry", which will re run the task, and * "Back" which will close the owningActivity. * //w ww . j av a 2s .c o m * @param owningActivity * @param task */ public static void createCineworldAPIErrorDialog(final Activity owningActivity, final ResurrectableTask task) { AlertDialog.Builder builder = new AlertDialog.Builder(owningActivity); builder.setMessage("Problem connecting to the Cineworld API"); builder.setCancelable(false); builder.setPositiveButton("Retry", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { task.resurrect(); } }); builder.setNegativeButton("Back", new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { owningActivity.finish(); } }); builder.create().show(); }
From source file:com.ruesga.rview.misc.ActivityHelper.java
public static boolean performFinishActivity(Activity activity, boolean forceNavigateUp) { if (activity == null) { return false; }//from w w w . j a v a 2 s. c o m boolean hasParent = activity.getIntent().getBooleanExtra(Constants.EXTRA_HAS_PARENT, false); if (forceNavigateUp || !hasParent) { Intent upIntent = NavUtils.getParentActivityIntent(activity); if (upIntent != null) { if (NavUtils.shouldUpRecreateTask(activity, upIntent)) { TaskStackBuilder.create(activity).addNextIntentWithParentStack(upIntent).startActivities(); activity.finish(); } else { NavUtils.navigateUpTo(activity, upIntent); } return true; } } activity.finish(); return true; }
From source file:air.com.snagfilms.cast.chromecast.utils.Utils.java
/** * A utility method to validate that the appropriate version of the Google * Play Services is available on the device. If not, it will open a dialog * to address the issue. The dialog displays a localized message about the * error and upon user confirmation (by tapping on dialog) will direct them * to the Play Store if Google Play services is out of date or missing, or * to system settings if Google Play services is disabled on the device. * //from www . java2 s . c om * @param activity * @return */ public static boolean checkGooglePlaySevices(final Activity activity) { final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity); switch (googlePlayServicesCheck) { case ConnectionResult.SUCCESS: return true; default: Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { activity.finish(); } }); dialog.show(); } return false; }
From source file:de.Maxr1998.xposed.maxlock.ui.LockActivity.java
@SuppressLint("WorldReadableFiles") public static void directUnlock(Activity caller, Intent orig, String pkgName) { try {// w ww. j a v a 2 s.c om //noinspection deprecation caller.getSharedPreferences(Common.PREFS_PACKAGES, MODE_WORLD_READABLE).edit() .putLong(pkgName + "_tmp", System.currentTimeMillis()).commit(); orig.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); caller.startActivity(orig); } catch (Exception e) { Intent intent_option = caller.getPackageManager().getLaunchIntentForPackage(pkgName); intent_option.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); caller.startActivity(intent_option); } finally { caller.finish(); } }