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
3 answers

How to show a dialog to confirm that the user wishes to exit an activity?

Am using below onBackpress method but this not working , am still click to back button repentantly came the same activity not exit current activity please solve my problem . @Override public void onBackPressed() { // TODO…
Kathirsk
  • 23
  • 5
-1
votes
1 answer

Exit App When Pressed Back Button after Login, but OnPressedBack keep Coming Back to First Page

I have 3 activity the first one is LandingActivity. This is the launcher activity when you open the app and not logged in, the second is SignInActivity and the third is HomeActivity, this activity is launched when you're already logged in and open…
mfpfakhri
  • 3
  • 2
-1
votes
1 answer

WebView onBackpressed() issue

I have created an app opening a website in webView. It was working fine but few days back I'm facing a issue that when a user above android version 6.0 presses a back button webview closes. Searched it on the internet found that webview is disabled…
-1
votes
1 answer

onDestroy() called when backbutton on actionbar is pressed

i have two activities, the first one contains a ListView of hotel list and the second one is a RecyclerView for displaying the details. I don't have a problem when i press it using my hardware back button the activity is resumed properly, the…
-1
votes
2 answers

Prevent to close dialog show automatically in the onBackPressed method

I Wan to Show a dialog to the user if click on back button. I Used this create the onBackPressed method like this: @Override public void onBackPressed() { super.onBackPressed(); if (isNew || !isReport) { if…
Ehsan
  • 2,676
  • 6
  • 29
  • 56
-1
votes
5 answers

On Back press method with different layouts

I have a single activity which has two buttons on it .each button opens a new layout .now if i will press back my application will close .but i want to return on Mainactivity and if the user presses back again then app is closed and if he does not…
Frankruss
  • 33
  • 8
-1
votes
1 answer

How to display several layouts by clicking several buttons?

Files: activity_main.xml (button1,button2) layout1.xml (button3,button4,button5) layout2.xml (button6,button7,button8) layoutA.xml (multiple CheckBox and textView) layoutB.xml (multiple CheckBox and textView) layoutC.xml (multiple CheckBox and…
-1
votes
4 answers

Android backpressed not working

I'm trying to build a simple login & registration application in android. My problem is that I want to handle backpressed() but it is not working. Example: I'm having 3 activities: signin, register and verify. What I need is if we back click on…
Isurendrasingh
  • 432
  • 7
  • 20
-1
votes
1 answer

Calling sourcefragment's onactivity result when hardware back pressed in target fragment android

I'm trying to call the source fragment onActivityResult() from the target fragment when hardware back button pressed and struck with the below code when used inside the target fragment class. Getting NPE in the code mentioned below. Please share…
Durga
  • 73
  • 12
-1
votes
4 answers

How can i return to specific previous activity on button pressed

I have a next problem. Let's assume i have three Activities : A, B and C. I can come from A to C, and from B to C. Then when i pressed button in Activity C i want to go back to the previous Activity, or A or B. I don't know which one was…
-1
votes
4 answers

Android unable to go back to the previous activity

I'm working in news feed like activity which contain list view. The list view contains multiple videos, When i click the video view i open another activity and play the video in fullscreen mode. When i back pressed the activity cannot move to…
Sasi
  • 445
  • 4
  • 19
-1
votes
4 answers

Closing previous Activity in Android

I am new to android and trying my level best. I am having an application with three activities, 1 login page 2. Home page 3. Registration Page The first activity loaded is login when a user gives correct user name and password I am allowing to Home…
Nitesh
  • 137
  • 1
  • 8
-1
votes
2 answers

How to disable on the App intro Activity

I have made slides using this library and its all working fine . I am calling my introduction slides right after Splash Activity. And the Intro of my app starts easily using this awesome library. but then I got the problem what I am doing public…
Allay Khalil
  • 674
  • 3
  • 11
  • 31
-1
votes
2 answers

How to get the current activity and compare it and do some action?

I have 2 activities and 4 fragments. I just want the code to close only when the user is on the MainActivity or welcome_fragment (I have named it that way) I wrote some pseudocode below to help you understand my question: Note: This code should be…
-1
votes
1 answer

Fragments: Replacing a fragment causes it to reinstantiate on back pressed

I am using one activity all fragment approach. Now I have a fragment A and when I go to fragment B I replace A in container with B with .replace(R.id.master_fragment_container_above_toolbar, fragment) .addToBackStack("") …
VipulKumar
  • 2,385
  • 1
  • 22
  • 28