Questions tagged [onbackpressed]

onBackPressed is a function called in the Android operating system when the user presses the back key.

onBackPressed is a function called in the Android operating system when the user presses the back key. By default the operating system simply finishes the currently active Android Activity, but it is possible to override the function to do whatever you want, including keeping the current Activity open.

580 questions
0
votes
5 answers

Generic handle OnBackPressed()

I have a BaseActivity() that have many activities and a BaseFragment() that have many fragments. Each activity contains 2-3 fragments and I need to make a generic method to handle each onBackPressed from all fragments (all - means all app screens)…
Choletski
  • 7,074
  • 6
  • 43
  • 64
0
votes
1 answer

super.finish() does not close the app

I have implemented yes / no dialogue that is shown when back button is pressed. if the user clicks "yes I want to leave" the app closes. everything works fine in my emulator, however when I installed the app on my phone, while clicking "yes" the app…
Ana Koridze
  • 1,532
  • 2
  • 18
  • 28
0
votes
2 answers

onback pressed data not showing in fragments

I am using navigation drawer in my app,I have fragments like F1,F2 and so on..and in every fragment I am parsing data and display in listview,everything is works fine if I go through my app like F1>F2>F3 and so on..but the issue is if I go from F3…
0
votes
4 answers

Back button restarts previus activity even after clearing activity stack

I am making an app where the user can logout by clicking the logout button. Before logging out the user is in the Activty A, then he clicks on the ogout button in the navigation drawer and this takes him to the Activity B( Login screen activity).…
varunkr
  • 5,364
  • 11
  • 50
  • 99
0
votes
3 answers

onbackpressed make my app close without confirmation

I'm new android developer, my app closes when I press back from any page in menu. I added this code with dialog but it is not working @Override public void onBackPressed() { super.onBackPressed(); FragmentManager fm =…
0
votes
2 answers

Can I use addToBackStack() when I only imported android.app.FragmentManager? Android

I'm trying to go back to my previous fragment so I tried using onBackPressed() and here is my code @Override public void onBackPressed() { if(getFragmentManager().getBackStackEntryCount() > 0) getFragmentManager().popBackStack(); …
Kairi San
  • 239
  • 1
  • 9
  • 23
0
votes
2 answers

How to keep informations in fragment after onBackPressed?

I'm newbie in android and I'm working with fragments. My problem: I have two fragments, "A" and "B", my fragment "A" is a complex form, the user can add and remove products, set customer information, payment method and more. My fragment "B" just…
0
votes
1 answer

onBackPressed() is not working

In One Activity class I am using different layouts. By disabling one layout I am moving to another layout. But I am facing an issue while pressing the back button. It is coming to the first layout while I am in third layout. Here is my Code: I…
User123
  • 13
  • 3
0
votes
3 answers

How to have an Activity notify a Fragment that the back button has been pressed

I have been researching this for a few days and have yet to find a working solution. There is lots of information available but because of my inexperience with Android I can't get any of the suggestions to work. I have an Activity with a stack of 3…
Sev
  • 883
  • 1
  • 14
  • 34
0
votes
1 answer

Android restore listview content

I have got two activities. In first you can input jobname and job place into inputtext views. First activity contains also navigation-draver menu (appearing from left side of screen). After clicking "Searc" button, results are shown in listview in…
ezekel
  • 1
  • 2
0
votes
3 answers

Android: pass data from activity with 3 fragments to previous activity

I'm building an Android App using Android Studio. Let's say I have Activity1 and Activity2. Activity2 has 3 fragments (3 tabs). I managed to pass data from Activity1 to Activity2 and then from Activity2 to it's fragments by using a Fragment…
0
votes
3 answers

My Application is not exiting when I double tap the Hardware Back Button

I'm trying to exit my application when the user double taps the HardWare Back Button, I've used the following code in my application: if (doubleBackToExitPressedOnce) { super.onBackPressed(); Dashboard_Activity.this.finish(); …
Parthiban M
  • 1,104
  • 1
  • 10
  • 30
0
votes
3 answers

onBackPressed with Fragments Android

I am trying to implement onBackPressed on an activity with 3 Fragments. My issue is I implemented a "press again to exit" after some time method however when back button is clicked twice it returns to the previous fragment, not quitting. This…
Bektaş Şahin
  • 71
  • 2
  • 3
  • 10
0
votes
2 answers

Stop sound file when back pressed in Android

I have some audio files in listview which I play them randomly. while the file is playing I want to go back by pressing the back button, so in method onBackpressed I put the following if(mMediaPlayer.isPlaying()) { …
user2629955
0
votes
1 answer

Find out where back button press is going

When user presses a back hardware button in my activity he will either be taken to a previous activity or to the home screen (depends on how he got into that activity in a first place). Is there a way to determine where exactly user will be taken…
src091
  • 2,807
  • 7
  • 44
  • 74