0

Automatic use of the Android back-button is between activities. I have a working app that uses a Cordova webview, which points to index.html file. The Question is: How do I use this back button to return from one view to the main view, and from the main view I want to confirm exit. Main ISSUE is to return from one view to main view. Thanks.

barq
  • 3,681
  • 4
  • 26
  • 39
Itamar
  • 885
  • 1
  • 9
  • 17

2 Answers2

0

You should override the back button so that it gives you the behavior you want.

Android - How To Override the "Back" button so it doesn't Finish() my Activity?

http://programmerguru.com/android-tutorial/how-to-change-the-back-button-behaviour/

Community
  • 1
  • 1
Daniel Gale
  • 643
  • 4
  • 13
  • Same here, these are examples for handling activities. I am looking to figure out how to handle views. – Itamar Jan 26 '16 at 15:46
0

You can overide the backbutton method from Activity

     @Override
     public boolean onBackPressed() {

        //Add your logic here

        return super.onBackPressed();
     }
Victor Gomes
  • 128
  • 10
  • This works for activities, show me how to use this with views. – Itamar Jan 26 '16 at 15:44
  • in Android, Views are classes that provide visual element, they don't have anything to do with the app navigation. An Activity or Fragment hosts a xml file that contains Views. You can do two things in your case: 1) Stay in the same Activity/Fragment and play with the Views visibility by using view.setVisibility(View.VISIBLE) or view.setVisibility(View.GONE). I do not recomend that you do this using the onBackPresses() because user expect the native behaviour from the back button. 2) You can spread the Views you are talking about into two different activities and achieve standard behaviour. – Victor Gomes Jan 27 '16 at 11:45