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
-1
votes
1 answer

onBackpress not calling when drawarMenu is closed in actionbarActivity?

I am developing Shopping Application allmost is ready, At main activity extend ActionBarActivity.on This activity leftDrawermenu, tabhost for Fragment. When drawer is open then onBackPress run and performe exitConfirmDialog but if drawer is closed…
-1
votes
1 answer

How to enable back press to close nav drawer on fragment only

I have implemented a navigation drawer for my fragment hence would like to know what's the best way to implement the back pressed feature for fragments only as well as where the code necessarily needs to go? I've used some back pressed code below…
wbk727
  • 8,017
  • 12
  • 61
  • 125
-1
votes
1 answer

onBackPressed in Activity

I am new to android and i was actually try to use onBackPressed using if method. For example: @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); if( pressed back button... ){ //…
-1
votes
4 answers

How to kill the app in android by pressing a button

I was displaying a dialog screen with an EditText field, cancel and ok button in the MainActivity class in onCreate method as below AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("User Login"); alert.setMessage("Enter your…
Shiva Krishna Bavandla
  • 25,548
  • 75
  • 193
  • 313
-1
votes
1 answer

UnsupportedOperationException - Random Error - OnBackPressed

I am getting unsupported operation exception while running my Android Code, RANDOMLY. Once this exception is thrown, my application is crashed. How to handle the same , and what is the basic cause of this EXCEPTION to be thrown. Example 1:…
Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
-2
votes
1 answer

Android) How can i use System back button?

I am trying to provide a back function to the browser launched in my program. My tablet doesn't have a bottom bar So I implemented it this way. import android.app.Activity; import android.app.ActivityManager; import…
Y Eng
  • 13
  • 3
-2
votes
1 answer

Managing fragment code from activity when back pressed

I have an Activity whose layout is a fragment which can be filled by different Fragments classes. The thing is that when I am in Fragment X and I press back, I would like to override onBackPressed method in order to execute a method asking the user…
mantc_sdr
  • 451
  • 3
  • 17
-2
votes
3 answers

How to back to mainactivity when I click on backbutton?

Override public void onBackPressed(){ if(drawer.isDrawerOpen(GravityCompat.START)){ drawer.closeDrawer(GravityCompat.START); }else { super.onBackPressed(); } } I have a nav drawer with some items and fragments. When I click on an…
-2
votes
2 answers

press back again to exit in android studio

how to implement press back again to exit in android studio, Pls. see My coding here. i'd checked all discussions here regarding this, but not working with my code. i've to make sure On back pressed, always go to home fragment before closing. Thank…
Rabee
  • 1
  • 1
-2
votes
1 answer

Back button is closing application instead of getting back to parent Activity

I'm new at Android developement. While pressing Back button, the user should be redirected to the HomeActivity but while pressing Back button, the application is being closed. What is being missed in my code? I have posted my main activity…
-2
votes
1 answer

Overriding onBackPressed() not working

In my app I want to allow the user to insert some data which later appears in a list. This aspect is organized as follows: From the Main Activity, the user can press a button which opens the Editor Activity. Here it's possible to construct the data.…
paola91
  • 339
  • 1
  • 5
  • 14
-2
votes
1 answer

Null object reference in .onBackPressed()

I have fatal exception in the method onBackPressed(): on a null object reference. How to handle the exception correctly? My code: @Override public void onBackPressed() { List fragments = getSupportFragmentManager().getFragments(); …
Roman
  • 1,045
  • 1
  • 12
  • 33
-2
votes
3 answers

Android: check if previous activity exists without putextra

I want if click on press back button, checking if previous exists I dont use put extra public void onBackPressed() { super.onBackPressed(); if (//Have activity){ // Go to home } else { // Go to register } }
My Name
  • 285
  • 1
  • 4
  • 18
-2
votes
3 answers

app close after onBackPressed - why?

Hi I have strange behavior of my activities. From MainActivity i start another activity and everything is cool. If I press back key the app doesn't go back to previous activity but it return me to desktop. I have not called destory or finish in…
svarog
  • 688
  • 1
  • 12
  • 29
-2
votes
1 answer

List View should not load onBackPressed

I have Three Activities Main Activity , Order Activity , Order Details Activity. Order Activity has a list view . On click of list View Order Details activity is opened but on back pressed from Order Details Activity the list view is loading again…
1 2 3
38
39