Back button closes app after navigation but not before - android

I've got an xamarin forms/prism app, and my hardware back button does nothing on the initial page.
If I navigate to another page, it closes the app as expected. If I navigate to the initial page again, it also closes the app - but not if the app just started.
Is there something I'm missing?
My class App mainly has an OnInitialized that navigates to the initial page:
protected override void OnInitialized()
{
NavigationService.NavigateAsync( "MyMasterDetail/MyNavigationPage/StartPage", animated: false );
}
On MyMasterDetail, there are buttons that navigate to MyNavigationPage/SettingsPage and other pages like that.
It doesn't matter if I use Android 5 in Emulator or Android 6 on a real device, the behaviour is the same.

When using a MasterDetail as your root, you are not actually navigating anywhere else. You are simply changing the Detail property of the MasterDetail to another Page. This is not a navigation action. So you are not really navigating. If you want to fake it, you need to add the INavigationPageOptions to your MyNavigationPage and set the ClearNavigationStackOnNavigation property to false. This will continuously push new pages onto the MasterDetailPage.Detail MyNavigationPage without clearing the stack (PopToRoot). Then this will allow your bac button to behave like you are wanting.

Related

How to keep the current page using Android WebView

I'm junior of android developer. (super beginner T_T)
I'm having trouble with Android Webview.
I am making a Hybrid app.
- when touch the app icon, it is linked to the webview(webview.loadurl(url)) directly.
When I click the home button after loading url and searching the web page (which is loaded through the webview),
and then re-click the app icon or touch the webview processing through click the home button long~.
I want to keep the page I've seen right before click the home button.
but It doesn't work.
Just reload the main index page.
I want...
Index page(login.jsp) -> A page -> B page -> Home button -> re-click the app or ~ -> B page
but unfourtunately, it works
Index page(login.jsp) -> A page -> B page -> Home button -> re-click the app or ~ -> Index page -> back key -> B page... It really strange.. \T_T
(back key -> B page :: Session didnt fired. may be keeped.)
I searched a lot about these problems.
Many people answered - Using Cookies and keep the session. but it also didn't work for me.
I know I didnt explain current problem well and show the code to you.
but I really really need help .
So please give me any hint.
Do I have to save the url adress which I searched last.?
Just to make sure we're talking about the same thing: when you say "home button," you mean the Android home button, not something on the web page, right?
When you press the home button, your activity is stopped; and it is restarted when the user returns to your app. The activity does not necessarily get destroyed and recreated, but it could, in which case the state is lost (except for state that the activity automatically saves).
I don't know about webview specifically, but if your activity is losing important state, such as the URL of the B page, you can save and restore it by overriding onSaveInstanceState() and onRestoreInstanceState().

Reg back button behavior in android

I am having a specific problem in my android app. I have 2 activities and the flow is from
Activity 1 to Activity 2.
I press back button from Activity 2 and then it goes to activity 1. This is great. But in some devices if I stay too long on activity 2(Like for days, I check it once in a while ) , and when I press back button it doesn't go back. So I guess history is cleared by android os for getting more memory.
I know that I can manually override onBackPressed() and achieve the functionality, but I need a perfect solution for this. so it will be like
If the history is all right let android handle back, If history is disturbed then I should be able to handle it.
IS there any way to check any issue with history?

Navigate to specific tab when app comes to foreground from the background

I am developing an app which has a FragmentActivity in which I have an ActionBar with 3 tabs at the top. In each tab I am loading a particular Fragment.
The thing I want to know is when my application is in foreground and suppose user was seeing the third tab and then he presses the home button, the application goes in background. When after some time when he taps on the application icon on the homescreen the application will come in foreground and at point of time I want the user to see a particular tab other than the third tab. (which is default behavior).
How can I achieve this ?
I tried using
actionBar.addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(SectionIterator)).setTabListener(this), true);
in onCreate() method but this works only when app is started for the first time and not when app is brought to foreground from the background.
Any insight is appreciated.
The way i accomplished this is as suggested by #Omer using the onResume() method.
Inside the onResume() method I have written the following code
ViewPager pager = (ViewPager)findViewById(R.id.pager);
int DefaultTabToBeSelected = vGetValueForDefaultTab();
pager.setCurrentItem(DefaultTabToBeSelected);
Use the onResume() method. this method gets called whenever the user comes back into your application after leaving it (but not killing it entirly)

PhoneGap/Cordova blank screen on pause/resume

I have a simple html/javascript app that starts and works up fine on an Android device. However, when the app is put in background by using the 'home button' and then brought back to the foreground by clicking on the app again - it starts with a blank screen (white blank screen on android ) and stays that way until the 'back button' is pressed.
Once the 'back button' is pressed the screen refreshes to the last page displayed by the app.
I am new to PhoneGap and I am sure there is something simple/fundamental that I am missing - in terms of how to handle the 'resume' event/etc.. I have followed the instructions provided on this link by Phil Mitchell http://wiki.phonegap.com/w/page/35501397/Tutorials (which is a great resource btw..)
Thanks.
Update :
After looking at the DroidGap code, I have tried to add the following line :-
super.setBooleanProperty("keepRunning", false);
But this does not seem to help. I am happy for the app to exit every time the home button is entered and then do a full restart when the app is clicked on the mobile.
Any help is much appreciated..
I was having the same problem and I want to share a hack that worked for me.
My app is based on ionic/angular/cordova and the android version was giving me a white screen around 50% the times on pause/resume.
When it happened, tapping anywhere on the screen or hitting the back button would make the screen to render again just fine.
I added a div tied to a scope variable named random, like this:
<body ng-app="starter" id="body">
<div>{{ random }}</div>
<ion-nav-view>
</ion-nav-view>
</body>
Then I added a listener inside my app.js to capture the resume event fired by cordova, to then change the random variable and call $apply(), like this:
document.addEventListener("resume", function() {
angular.element(document.querySelector('#body')).scope().random = Math.random();
angular.element(document.querySelector('#body')).scope().$apply();
})
Since the ion-nav-view takes over the whole screen that div never shows up, but angular doesn't know that and refreshes the page, causing the whole thing to work.
(I tried to tie the variable to an invisible element but then angular doesn't refresh the page)
I hope this helps someone!
There seem to be issues around rendering the pages thru PhoneGap and 'Dialog'ing thru Client side FB authentication flow using the JS SDK. If I disable the client side authentication, then the rendering and display of the page works very well, when the app is brought to foreground from background (pause/resume/etc).
I am assuming that the page will need to sense that it is being displayed over a mobile device and use the IOS or Androi SDK for client side authentication.. (if/when I get around to testing that, I update the answer - if there is anybody who has any more light to shed, please feel free to embellish).
If you still say "I am happy for the app to exit every time the home button is entered and then do a full restart when the app is clicked on the mobile." then go for it.
#Override
protected void onStop(){
super.onStop();
}
Try this from where you create activity or from the class which "extends DroidGap".

Android End to End testing with calabash

I am new to using calabash for android, which is a end to end testing framework for android. Iam trying to test a feature where on pressing a button in my app I am taken back to the android home screen. Could someone help me with the test for this scenario? Here is what I have till now
Feature: Return to Home Screen
Scenario: As a user
When I press the "GO" button
Then I should see "HomeActivity" screen appear
I am stuck at the second line. I have tried several alternatives like trying to use the id (Don't think I got the correct id. Does the android home activity have a predefined id?) or different names to test if the home activity appears.
I've created a new action to do exactly that on my github branch
For TabActivities it returns the tag of the current tab.
For other Activities it returns the class name.
actual_activity = performAction('get_activity_name')['bonusInformation']
raise Exception "Expected #{expected_activity} activity but was #{actual_activity}" unless actual_activity == expected_activity

Categories

Resources