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".
Related
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.
I am developing an android application using Cordova and Onsenui, in whic i want to disable the android back button handler.
I've tried this
answer ,but didnt work for me
Here is my code its placed on top of my app.js file
ons.ready(function() {
ons.disableDeviceBackButtonHandler();
});
Supposing that you are using <ons-navigator var="myNavigator"></ons-navigator>, have you already tried something like this?
// To disable a navigator back button handler
myNavigator.getDeviceBackButtonHandler().disable();
You should also not forget to add cordova.js reference to your index page. You don't need to paste the file, it will be generated automatically every time you deploy a Cordova app.
<script src="cordova.js"></script>
If you don't add it, it will not be possible to manipulate the BackButton behavior.
Default behavior:
Main page: closes the app.
Other pages: goes back.
Disabling the handler, the app will be closed every time you press the button, regardless the page.
I tried adding function to override current back button behaviour, which is exactly the same as pressing back button (left arrow) in browser. This often goes to the view that is forward instead of going back. I understand that this is how WebView would handle back button action if it is not override.
I was surprised that Android back button doesn't work the same as ion-nav-view standard back button, so I found the code that is responsible in ionic.bundle.js:
// Triggered when devices with a hardware back button (Android) is clicked by the user
// This is a Cordova/Phonegap platform specifc method
function onHardwareBackButton(e) {
console.log('check'); //this never fires
var backView = $ionicHistory.backView();
if (backView) {
// there is a back view, go to it
backView.go();
} else {
// there is no back view, so close the app instead
ionic.Platform.exitApp();
}
e.preventDefault();
return false;
}
console.log('check2'); //this fires
$ionicPlatform.registerBackButtonAction(
onHardwareBackButton,
IONIC_BACK_PRIORITY.view
);
I tested it on Galaxy S5.
Any hints how to make this work?
Why are you not using : $ionicHistory.goBack() instead of backView.go(); ?
From doc goBack is the way to navigate through history
I think you are adding the the back view as a new view upon the stack by calling
backView.go();
you should, instead call
$ionicHistory.goBack();
Is it possible you're using Ionic View to run the app? If so, that's been one of the many different-than-native issues that I've run into while using Ionic View. I couldn't get the back button behavior to work as intended within Ionic View, among other things.
I've since switched to testing my app with others using Google Play Alpha/Beta Testing. That will get the app running on every tester's device the way it will actually appear.
Even though I had no errors like:
cordova is undefined
I added the following to my index.html and it started working
<script src="cordova.js"></script>
I am working with phonegap and jquery mobile but am having problems with going back on pages. There are four pages:
Splash
Login
Main
SubMain
So Lets say the flow goes like this always hit the splash screen first. If a user has never logged before, they are shown the login screen, if they have then they are shown the main page. Here's a scenario:
A new user will navigate like this:
Splash
Login
Main
SubMain
Now from Submain screen, if they want to exit they will hit the back button until the they exit. However this route will take them through the Login page and the Splash screen again, when I want them to exit the app when they hit back on the main screen.
Is there anyway to make the user exit when pressing back on Main?
I realize I could avoid this by disabling the back button and adding an exit button.
I'm not sure if this matters or not, but all my pages are in one single html file separated by divs with the data-role="page" attribute
I think navigator.app.exitApp() is what you're looking for. As we keep track of the history manually our helper function looks similar to this:
function backKeyDown(){
if(historyContainsInfo(){
popHistory();
}else{
navigator.app.exitApp();
}
}
and is registered via document.addEventListener("backbutton", backKeyDown, true);
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