onbackpressed

onBackPressed function not working under IMMERSIVE STICKY mode

吃可爱长大的小学妹 提交于 2019-12-11 02:45:37
问题 I'm using Immersive Mode for an activity with videoView inside. My goal is when touch on screen, the media controller and the system control bar show or disappear together. Everything works fine now. The problem is I can't leave activity properly. When I press the back button once, the system bar just hide again and nothing happens. I have to press twice to exit the activity. I don't know why. Here's my code. I use an FullScreenActivity() activity to define IMMERSIVE MODE: @TargetApi(Build

Clicking back button twice to exit an activity with rxjava

旧时模样 提交于 2019-12-10 17:57:15
问题 Looking for a subtle rx approach to exit an activity while pressing back button two times. boolean doubleBackToExitPressedOnce = false; @Override public void onBackPressed() { if (doubleBackToExitPressedOnce) { super.onBackPressed(); return; } this.doubleBackToExitPressedOnce = true; Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show(); new Handler().postDelayed(new Runnable() { @Override public void run() { doubleBackToExitPressedOnce=false; } }, 2000); } 回答1: I

How to detect backbutton/home press from a service like messenger chat head service?

本秂侑毒 提交于 2019-12-09 11:41:41
问题 I have been looking through several stackoverflow question to find out how can I listen to backpress button on a service using windows manager. Most of the answers proposes that it's not possible, however I can see that messenger handle it very well. How does messenger handle the backpress button on it's head chat service? (Or I am completely wrong and they are not a service using windows manager?) 回答1: To achieve what you need, you need to extend some ViewGroup that you are going to use as a

Can not perform this action after onSaveInstanceState on super.onBackPressed()

孤人 提交于 2019-12-08 14:46:29
问题 I am displaying an interstitial ad when the user presses back to exit the application: mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdClosed() { onBackPressed(); //line 98 } }); requestNewInterstitial(); private void requestNewInterstitial() { AdRequest adRequest = new AdRequest.Builder().build(); mInterstitialAd.loadAd(adRequest); } @Override public void onBackPressed() { if (mInterstitialAd.isLoaded()) { mInterstitialAd.show(); } else { super.onBackPressed(); /

how back to the main activity in android?

会有一股神秘感。 提交于 2019-12-07 14:24:43
问题 I have a MainActivity "A", which have a button that launch activity "B", and activity "B" have another button that launch activity "C". In the activities B and C, both have onBackPressed() method, which appears an AlertDialog asking if the user wants to return to MainActivity . If they press yes, the program should show MainActiviy. The question is: in activity B, i have not problem, simply call the finish() method, and MainActivity appears, but the problem is in activity C, if i call a

Android Double Back Press to close the app having fragments

烈酒焚心 提交于 2019-12-07 05:15:25
问题 I followed this tutorial and certain similar answers on SO. My present onBackPressed code is as follows - private static final int TIME_DELAY = 2000; private static long back_pressed; @Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { int fragments = getFragmentManager().getBackStackEntryCount(); if (fragments > 0) { super.onBackPressed(

Exit Full Screen Video Mode on Back Press

拈花ヽ惹草 提交于 2019-12-06 07:20:32
I just started with this GMF example provided by Google. I would like to know How can I Exit Full Screen Video Mode by doing tap on back button, I tried using below code, but did not get any success, here you can see the actual code of MainActivity.java boolean isFullScreen = false; // globally declared @Override public void onGoToFullscreen() { isFullScreen = true; videoListView.setVisibility(View.INVISIBLE); } @Override public void onReturnFromFullscreen() { videoListView.setVisibility(View.VISIBLE); } @Override public void onBackPressed() { if(isFullScreen) { onReturnFromFullscreen(); }

how back to the main activity in android?

江枫思渺然 提交于 2019-12-05 18:31:20
I have a MainActivity "A", which have a button that launch activity "B", and activity "B" have another button that launch activity "C". In the activities B and C, both have onBackPressed() method, which appears an AlertDialog asking if the user wants to return to MainActivity . If they press yes, the program should show MainActiviy. The question is: in activity B, i have not problem, simply call the finish() method, and MainActivity appears, but the problem is in activity C, if i call a finish() method, the program is back to activity B. How back to MainActivity from activity C?? try this on

Update selected state of navigation drawer after back press

别来无恙 提交于 2019-12-05 14:46:27
问题 Whats the proper way to handle the selected state of the navigation drawer after back press? I have a navigation drawer with n entries (in a listview) like the SDK sample in Android Studio. When i click on the navigation drawer entries i want them to be added to the back stack, so i can move back to them. In onNavigationDrawerItemSelected(int pos) i have FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); if

Android Double Back Press to close the app having fragments

ⅰ亾dé卋堺 提交于 2019-12-05 08:33:54
I followed this tutorial and certain similar answers on SO. My present onBackPressed code is as follows - private static final int TIME_DELAY = 2000; private static long back_pressed; @Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { int fragments = getFragmentManager().getBackStackEntryCount(); if (fragments > 0) { super.onBackPressed(); } else { if (back_pressed + TIME_DELAY > System.currentTimeMillis()) { super.onBackPressed(); } else