Back button unloads application after changes currentState of Android Application AIR - android

I am creating an application. At one view I have three states. If I changes state and than back button pressed it unloads the application.
I am developing it in Adobe AIR.
any one have any idea how to fix it.
Thanks

States are not views, they do not get stacked in the navigator. Back button will never go backward for your states. The back button will drop the view you push until it reach the view 0, then it'll exit the application. You can monitor what's going on with the back button by listening like this:
systemManager.stage.addEventListener(KeyboardEvent.KEY_UP, handleCustomDeviceKeyUpHandler,false,10000);
private function handleCustomDeviceKeyUpHandler(event:KeyboardEvent):void {
trace("handleCustomDeviceKeyUpHandler()")
var key:uint = event.keyCode;
if (key == Keyboard.BACK) {
event.preventDefault(); //Comment if you don't want to prevent.
}
}

Related

Xamarin forms : Stop page being accessible from hardware back button

I am using xamarin forms prism.
Quick info : I have a page that contains information, this page the user can delete along with its information, this page is an instance of a page called saved conversation, think of each instance as a saved email, you may have many of the one type and are made dynamically.
The user deletes one saved conversation and this also removes an instance for that page, after they have deleted it, it will send them back to one of two pages every time. But they are still able to access this deleted saved conversation page using the hardware back button (Android), either by clicking it straight after they were force navigated back or navigating the app a bit and then pressing the back button multiple times. I would use something such as...
protected override bool OnBackButtonPressed()
{
return true;
}
But I want the back button to work for other pages and only not work if the previous page is an instance of the Saved conversation page, regardless if it has been deleted or not (As I think I may be able to figure out if it was deleted or not myself, just need to detect the page the hardware back button is going to send the user to, I think).
This might fall under a user experience decision over a technical workaround; but it sounds to me like this page you have might be a good candidate to be a Modal Page.
Navigating away from the modal page (popping it from the stack) should accomplish the same goal you are aiming for: not being able to navigate "back" to that page.
What I have done was add this code to all the pages in which I did not want the user to be able to go back. But it would only limit them from going back if the previous page is one of the two shown below. If it isn't then the back button works.
What I did note was you have to make sure modalNavigation is set to false when navigating to the pages (in my case conversation and saved conversation) otherwise they won't appear on the navigation stack to check against.
/// <summary>
/// Will override the harware back button.
/// </summary>
/// <returns> True if it can't go back false if it can.</returns>
protected override bool OnBackButtonPressed()
{
int count = this.Navigation.NavigationStack.Count;
bool shouldntGoBack = false;
if (count > 1)
{
string previousPage = this.Navigation.NavigationStack[count - 2].ToString();
if (previousPage == "NGT.Views.ConversationPage" || previousPage == "NGT.Views.SavedConversationPage")
{
shouldntGoBack = true;
}
}
return shouldntGoBack;
}

Android hardware back button action never fires (Ionic)

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>

Phonegap android app exiting after clicking on back button even though the user is logged-in

I am creating a simple android Login app using PhoneGap and Eclipse and facing problem with android back button.
I want to control the behaviour of back button such as :
If user has been logged in and he/she pressed on back button app should be minimized.
If not logged-in app should get closed after clicking on back button.
I scoured the lots of posts regarding with "Minimizing the app after clicking back button"
but didn't got the solution. Any solution?
You can handel phonegap back button events with the help of
document.addEventListener("backbutton", onBackButtonFire, false);
Handle Application Pause
document.addEventListener("pause", onPause, false);
Handle Application Resume
document.addEventListener("resume", onResume, false);
Define Back Function
function onBackButtonFire()
{
// Check if user is logged in or not.?
if(localStorage.Checklogin=="true")
{
// minimize app here
}
else
{
// Exit the app
navigator.app.exitApp();
}
}
function onPause()
{
//handel pause;
}
function onResume()
{
// handel resume of app
}
store your information about is user logged in in localStorage.Checklogin .
you can find manually pause the application using this link
Manually Make application Pause
The default behaviour of the backbutton is navigate back in the history and to close the app if ther's no more history.
In Cordova/Phonegap, you can build your own event handler for the back button.
See doc here : http://cordova.apache.org/docs/en/3.5.0/cordova_events_events.md.html#backbutton
Then in your event handler, you would use the history api to either navigate back if you're not on the first page or perform your own logic to close/reduce the app depending on user logged or not.
It's easy to close the app : navigator.app.exitApp();
But to reduce it, I don't know if there's an easy thing in phonegap. And I honestly don't think it makes any sence as in android there's the home button which basically reduces the app.
What I do in my app is that if user is logged, I display a dialog to ask the user if he wants to disconnect.

Sencha touch select field is not closing when we clicks the back button in android device

i have done application using sencha touch 2. Back page logic is maintaining through the routes in application. Back logic is working very nice in both ipad/android device. One issue is causing problem in android device when we clicks the back button in device not closing popup select field popup.In this page i have select field, when clicks the select field it will show select field popup with option cancel and done, i wont select any option directly i will press the back button in android device. it is not closing popup, but it is going to back previous page but select field popup remains opened not closing. i need to close bottom select field popup when clicks the back button in android device. Can any one tell me how to achieve this one. I have attached screen shot of select field popup for more reference.
Without seeing any code I'm guessing that you've either created an own popup or that you've set usePicker to false on the selectfield.
Why so? Wouldn't set usePicker: true, suffice for your solution?
Anyway, do deal with the problem at hand and with the information you've provided what I would have done is to set a id on your popup (or css class) that enables you to identify it and in any relevant route function hide them if they are visible
var popupElement = findYourPopup(); //Ext.getCmp("popup") || ParentEl.query("cssclass") etc.
if (popupElement && !popupElement.isHidden()) {
popupElement.hide();
}
Hope that this will help you!
You can also handle hardware back button like this:
if (Ext.os.is('Android')) {
document.addEventListener("backbutton", Ext.bind(onBackKeyDown, this), false);
function onBackKeyDown(eve) {
eve.preventDefault();
//do something
alert('back button pressed');
}
}

Is it possible to listen for touches on the physical Android back button?

I couldn't find it in the docs, is there a module, or some other way to catch events from the android back button? If not it would be a nice and probably quick module to add.
No: the back button just pops you one item back in the history stack. You do something like change the hash fragment to track navigation through your app (frameworks like Backbone.js can do this for you automatically).
The reason we've taken that approach is there's no hardware back button on iOS so we're wary of setting people up to rely on it in their app, only for the app to be fundamentally broken on that platform: we're aiming for consistency of completeness at the moment.
Update: due to popular demand, we've added support for controlling the back button behaviour on Android: http://docs.trigger.io/en/v1.4/modules/event.html#backpressed-addlistener - note backPressed.preventDefault too.
The event handler is passed a function which, when invoked, closes the app, so you could have code like:
forge.event.backPressed.addListener(function (close) {
if (atHomeScreen) {
close();
}
}

Categories

Resources