List of usage examples for android.app Activity finish
public void finish()
From source file:net.goldenspiral.fetlifeoss.ui.fragments.FetLifeFragment.java
public void onBackPressed() { Activity activity = getActivity(); if (activity != null) activity.finish(); }
From source file:com.kasungunathilaka.sarigama.ui.PlayerActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, // WindowManager.LayoutParams.FLAG_FULLSCREEN); Intent intent = getIntent();/*from www .ja v a 2 s. co m*/ audioFile = intent.getStringExtra(AUDIO_URL); final String coverImage = intent.getStringExtra(IMG_URL); final String audioTitle = intent.getStringExtra(AUDIO_TITLE); final String audioArtist = intent.getStringExtra(AUDIO_ARTIST); // mediaPlayer = new MediaPlayer(); try { // mediaPlayer.setDataSource(audioFile); // mediaPlayer.prepareAsync(); dialog = new ProgressDialog(PlayerActivity.this); dialog.setMessage(getString(R.string.loading)); dialog.setCancelable(false); dialog.getWindow().setGravity(Gravity.CENTER); dialog.show(); setContentView(R.layout.activity_player); ((TextView) findViewById(R.id.tvTitle)).setText(audioTitle); ((TextView) findViewById(R.id.tvArtist)).setText(audioArtist); ImageView mImageView = (ImageView) findViewById(R.id.coverImage); String image_url = coverImage; Picasso.with(getApplicationContext()).load(image_url).into(mImageView); // mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { // public void onPrepared(final MediaPlayer mp) { // mp.start(); // ((CircleImageView) findViewById(R.id.ibPlay)).setImageResource(R.drawable.ic_pause_white); // seekBar = (SeekBar) findViewById(R.id.seekBar); // mRunnable.run(); // dialog.dismiss(); // } // }); // // mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { // @Override // public void onCompletion(MediaPlayer mp) { // ((CircleImageView) findViewById(R.id.ibPlay)).setImageResource(R.drawable.ic_play_white); // } // }); } catch (Exception e) { Activity a = this; a.finish(); Toast.makeText(this, getString(R.string.file_not_found), Toast.LENGTH_SHORT).show(); } broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { switch (intent.getAction()) { case ON_PREPARED: ((CircleImageView) findViewById(R.id.ibPlay)).setImageResource(R.drawable.ic_pause_white); seekBar = (SeekBar) findViewById(R.id.seekBar); mRunnable.run(); dialog.dismiss(); break; case ON_COMPLETED: ((CircleImageView) findViewById(R.id.ibPlay)).setImageResource(R.drawable.ic_play_white); seekBar.setProgress(0); break; } } }; }
From source file:com.google.samples.apps.topeka.fragment.SignInFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { assurePlayerInit();//w w w . j a v a 2 s.c om checkIsInEditMode(); if (mPlayer == null || edit) { view.findViewById(R.id.empty).setVisibility(View.GONE); view.findViewById(R.id.content).setVisibility(View.VISIBLE); initContentViews(view); initContents(); } else { final Activity activity = getActivity(); CategorySelectionActivity.start(activity, mPlayer); activity.finish(); } super.onViewCreated(view, savedInstanceState); }
From source file:com.franceaoc.app.ui.fragment.NearestCommunesListFragment.java
/** * {@inheritDoc }// w ww .j a v a 2 s . c o m */ @Override public void onAttach(Activity activity) { super.onAttach(activity); try { // check that the containing activity implements our callback mContainerCallback = (CommuneListEventsCallback) activity; mActivity = activity; } catch (ClassCastException e) { activity.finish(); throw new ClassCastException(activity.toString() + " must implement AppListEventsCallback"); } }
From source file:net.zionsoft.obadiah.ui.fragments.TranslationListFragment.java
private void initializeUi() { mSwipeContainer.setColorSchemeResources(R.color.dark_cyan, R.color.dark_lime, R.color.blue, R.color.dark_blue);//from ww w .j a va 2 s .c om mSwipeContainer.setOnRefreshListener(this); // workaround for https://code.google.com/p/android/issues/detail?id=77712 mSwipeContainer.setProgressViewOffset(false, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources().getDisplayMetrics())); mSwipeContainer.setRefreshing(true); mTranslationListAdapter = new TranslationListAdapter(getActivity(), mCurrentTranslation); mTranslationListView.setAdapter(mTranslationListAdapter); mTranslationListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (!isAdded()) { return; } final Pair<TranslationInfo, Boolean> translation = mTranslationListAdapter.getTranslation(position); if (translation == null) { return; } if (translation.second) { Analytics.trackTranslationSelection(translation.first.shortName); mPreferences.edit() .putString(Constants.PREF_KEY_LAST_READ_TRANSLATION, translation.first.shortName) .apply(); Activity activity = getActivity(); activity.finish(); activity.overridePendingTransition(R.anim.fade_in, R.anim.slide_out_left_to_right); } else { downloadTranslation(translation.first); } } }); registerForContextMenu(mTranslationListView); }
From source file:net.zionsoft.obadiah.ui.fragments.TranslationListFragment.java
private void loadTranslations(final boolean forceRefresh) { mTranslationListView.setVisibility(View.GONE); mBible.loadTranslations(forceRefresh, new Bible.OnTranslationsLoadedListener() { @Override/*from w w w . j a va 2 s . c om*/ public void onTranslationsLoaded(List<TranslationInfo> downloaded, List<TranslationInfo> available) { if (!isAdded()) return; if (downloaded == null || available == null) { DialogHelper.showDialog(getActivity(), false, R.string.dialog_retry_network, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { loadTranslations(forceRefresh); } }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final Activity activity = getActivity(); activity.finish(); activity.overridePendingTransition(R.anim.fade_in, R.anim.slide_out_left_to_right); } }); return; } mSwipeContainer.setRefreshing(false); AnimationHelper.fadeIn(mTranslationListView); mTranslationListAdapter.setTranslations(downloaded, available); mTranslationListAdapter.notifyDataSetChanged(); } }); }
From source file:org.firebears.scouting2846.TeamDetailFragment.java
private void onTeamLoaded(Cursor c) { if (c == null) { Log.d(TAG, "team not found"); Activity a = getActivity(); if (a != null) { Intent intent = new Intent(); intent.putExtra(TeamListActivity.ERROR_CODE, R.string.invalid_number); a.setResult(Activity.RESULT_CANCELED, intent); a.finish(); }// w ww. j av a 2s . c o m return; } Log.d(TAG, "team loaded"); if (null == root_view) return; Toolbar bar = (Toolbar) getActivity().findViewById(R.id.detail_toolbar); if (bar != null) { int team_num = c.getInt(c.getColumnIndex(Team.COL_TEAM_NUMBER)); String nick = c.getString(c.getColumnIndex(Team.COL_NICKNAME)); bar.setTitle("" + team_num + ' ' + nick); } setViewText(R.id.locality, c, Team.COL_LOCALITY); setViewText(R.id.region, c, Team.COL_REGION); setViewText(R.id.country, c, Team.COL_COUNTRY); TextView tv = setViewText(R.id.team_website, c, Team.COL_WEBSITE); Linkify.addLinks(tv, Linkify.WEB_URLS); tv = (TextView) root_view.findViewById(R.id.team_rookie_year); String t = c.getString(c.getColumnIndex(Team.COL_ROOKIE_YEAR)); if (t != null) tv.setText(getText(R.string.rookie_year) + " " + t); initScoutingSpinner(); setViewText(R.id.team_motto, c, Team.COL_MOTTO); }
From source file:de.teambluebaer.patientix.activities.LoginActivity.java
/** * Deactive kioskmode with press on exit button if you * entered the PIN-Code/* w w w.j ava 2s. c o m*/ * * @param v Parameter to change something in view */ public void onClickButtonExit(View v) { if (passwordHash(editTextPassword.getText().toString()).equals(Constants.PIN)) { PrefUtils.setKioskModeActive(false, Constants.CURRENTACTIVITY); Constants.CURRENTACTIVITY.finish(); PrefUtils.setKioskModeActive(false, this); for (Activity activity : Constants.LISTOFACTIVITIES) { PrefUtils.setKioskModeActive(false, activity); activity.finish(); } System.exit(0); } else { editTextPassword.setText(""); Toast.makeText(this, "Falscher PIN!!!", Toast.LENGTH_LONG).show(); } }
From source file:codewrencher.gifit.tools.ErrorDialog.java
/** * On class instance created callback/* ww w. ja va 2 s.c o m*/ * @param savedInstanceState: Stores saved parameters * @return */ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); return new AlertDialog.Builder(activity).setMessage(getArguments().getString(ARG_MESSAGE)) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { activity.finish(); } }).create(); }
From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java
/** * Installs CustomActivityOnCrash on the application using the default error activity. * * @param context Context to use for obtaining the ApplicationContext. Must not be null. *///from ww w. j ava 2s . c o m public static void install(Context context) { try { if (context == null) { Log.e(TAG, "Install failed: context is null!"); } else { if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { Log.w(TAG, "CustomActivityOnCrash will be installed, but may not be reliable in API lower than 14"); } //INSTALL! final Thread.UncaughtExceptionHandler oldHandler = Thread.getDefaultUncaughtExceptionHandler(); if (oldHandler != null && oldHandler.getClass().getName().startsWith(CAOC_HANDLER_PACKAGE_NAME)) { Log.e(TAG, "You have already installed CustomActivityOnCrash, doing nothing!"); } else { if (oldHandler != null && !oldHandler.getClass().getName().startsWith(DEFAULT_HANDLER_PACKAGE_NAME)) { Log.e(TAG, "IMPORTANT WARNING! You already have an UncaughtExceptionHandler, are you sure this is correct? If you use ACRA, Crashlytics or similar libraries, you must initialize them AFTER CustomActivityOnCrash! Installing anyway, but your original handler will not be called."); } application = (Application) context.getApplicationContext(); //We define a default exception handler that does what we want so it can be called from Crashlytics/ACRA Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, final Throwable throwable) { Log.e(TAG, "App has crashed, executing CustomActivityOnCrash's UncaughtExceptionHandler", throwable); if (hasCrashedInTheLastSeconds(application)) { Log.e(TAG, "App already crashed in the last 2 seconds, not starting custom error activity because we could enter a restart loop. Are you sure that your app does not crash directly on init?", throwable); if (oldHandler != null) { oldHandler.uncaughtException(thread, throwable); return; } } else { setLastCrashTimestamp(application, new Date().getTime()); if (errorActivityClass == null) { errorActivityClass = guessErrorActivityClass(application); } if (isStackTraceLikelyConflictive(throwable, errorActivityClass)) { Log.e(TAG, "Your application class or your error activity have crashed, the custom activity will not be launched!"); if (oldHandler != null) { oldHandler.uncaughtException(thread, throwable); return; } } else if (launchErrorActivityWhenInBackground || !isInBackground) { final Intent intent = new Intent(application, errorActivityClass); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); throwable.printStackTrace(pw); String stackTraceString = sw.toString(); //Reduce data to 128KB so we don't get a TransactionTooLargeException when sending the intent. //The limit is 1MB on Android but some devices seem to have it lower. //See: http://developer.android.com/reference/android/os/TransactionTooLargeException.html //And: http://stackoverflow.com/questions/11451393/what-to-do-on-transactiontoolargeexception#comment46697371_12809171 if (stackTraceString.length() > MAX_STACK_TRACE_SIZE) { String disclaimer = " [stack trace too large]"; stackTraceString = stackTraceString.substring(0, MAX_STACK_TRACE_SIZE - disclaimer.length()) + disclaimer; } if (enableAppRestart && restartActivityClass == null) { //We can set the restartActivityClass because the app will terminate right now, //and when relaunched, will be null again by default. restartActivityClass = guessRestartActivityClass(application); } else if (!enableAppRestart) { //In case someone sets the activity and then decides to not restart restartActivityClass = null; } String userLogString = ""; while (!userLogs.isEmpty()) { userLogString += userLogs.poll(); } intent.putExtra(EXTRA_STACK_TRACE, stackTraceString); intent.putExtra(EXTRA_USER_ACTION_TRACE, userLogString); intent.putExtra(EXTRA_RESTART_ACTIVITY_CLASS, restartActivityClass); intent.putExtra(EXTRA_SHOW_ERROR_DETAILS, showErrorDetails); intent.putExtra(EXTRA_EVENT_LISTENER, eventListener); intent.putExtra(EXTRA_IMAGE_DRAWABLE_ID, defaultErrorActivityDrawableId); intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); if (eventListener != null) { eventListener.onLaunchErrorActivity(); } application.startActivity(intent); } } final Activity lastActivity = lastActivityCreated.get(); if (lastActivity != null) { //We finish the activity, this solves a bug which causes infinite recursion. //This is unsolvable in API<14, so beware! //See: https://github.com/ACRA/acra/issues/42 lastActivity.finish(); lastActivityCreated.clear(); } killCurrentProcess(); } }); if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { application .registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() { int currentlyStartedActivities = 0; DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) { if (activity.getClass() != errorActivityClass) { // Copied from ACRA: // Ignore activityClass because we want the last // application Activity that was started so that we can // explicitly kill it off. lastActivityCreated = new WeakReference<>(activity); } userLogs.add(dateFormat.format(new Date()) + " " + activity.getLocalClassName() + " created\n"); } @Override public void onActivityStarted(Activity activity) { currentlyStartedActivities++; isInBackground = (currentlyStartedActivities == 0); //Do nothing } @Override public void onActivityResumed(Activity activity) { userLogs.add(dateFormat.format(new Date()) + " " + activity.getLocalClassName() + " resumed\n"); } @Override public void onActivityPaused(Activity activity) { userLogs.add(dateFormat.format(new Date()) + " " + activity.getLocalClassName() + " paused\n"); } @Override public void onActivityStopped(Activity activity) { //Do nothing currentlyStartedActivities--; isInBackground = (currentlyStartedActivities == 0); } @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) { //Do nothing } @Override public void onActivityDestroyed(Activity activity) { userLogs.add(dateFormat.format(new Date()) + " " + activity.getLocalClassName() + " destroyed\n"); } }); } Log.i(TAG, "CustomActivityOnCrash has been installed."); } } } catch (Throwable t) { Log.e(TAG, "An unknown error occurred while installing CustomActivityOnCrash, it may not have been properly initialized. Please report this as a bug if needed.", t); } }