Actionscript 3 Android Device 'Back' Key - android

This is the code I have for a Android device BACK button:
function handleKeyOut(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.BACK)
{
event.preventDefault();
gotoAndStop(2);
}
}
When I test the code on my Samsung Galaxy Mega 6.3 phone (Kit Kat), hitting the BACK key button causes the app to not show on the screen yet still run in the background. My app does have a frame 2...Flash debugger gives no errors so I'm thinking maybe it's Kit Kat (since I've had sound issues with Kit Kat already).
I would like for the BACK key to take the user to frame 2. If I code a 'Native Application Exit' for the BACK key it works fine...the BACK key just won't accept the gotoAndStop command.
I'm researching this now so thanks if anyone can put some insight into this.

THIS WORKS...
stage.addEventListener(KeyboardEvent.KEY_DOWN, buttonPressed);
function buttonPressed(event:KeyboardEvent):void
{
if (event.keyCode == Keyboard.BACK)
{
event.preventDefault();
stage.removeEventListener(KeyboardEvent.KEY_DOWN, buttonPressed);
gotoAndStop("home");
}
}

Related

React native - When i lock the screen while API call loading, App process stopped

I am trying to show a large list in react native - Expo. When I lock the screen while data loading via API. App State changed from "Active" to "Inactive".
When I return to an active state, no data has been loaded. The App processes are stopped. ListEmptyComponent renders the ActivityIndicator. It is loading indefinitely. It occurs only in android build.
I tried to recall the API by AppState.
const handleAppStateChange = nextAppState => {
console.log(nextAppState);
if (nextAppState === 'active') {
console.log(JSON.stringify(Store.apiCall));
// "Store.apiCall" has data about last API Call and its status.
if (Store.apiCall.status === codes.PENDING || Store.apiCall.status === codes.ERROR) {
api(Store.apiCall.payload);
}
}
setAppState(nextAppState);
};
Still it doesn't works..
This happening because of the battery optimization features of newer Android versions. The only fix would be to ask the user to disable the battery optimization for your app by redirecting them to your app settings or you can use a node package like this one:
https://www.npmjs.com/package/react-native-disable-battery-optimizations
Also, if you dont want your device to sleep if its in active state you can use something like this:
https://www.npmjs.com/package/react-native-keep-awake
Hope this helps :)

Android Progressive Web App - Add to home screen appears even after install

We have a Progressive Web App that prompts the user with the "Add to home screen" banner.
Adding to the homescreen works great, but after the user launches the page from the Home Screen it will sometimes still prompt them to install the app again. I'm posting here because all the resources I have found don't talk about this issue or how to solve it.
TL;DR Launching the app from the home screen still asks them to install the app with the "Add to home screen" prompt.
As suggested by #Mr.Rebot, I developed a little piece of code to solve the problem.
This is the result code:
window.addEventListener("beforeinstallprompt", (ev) => {
if (isStandalone()) {
// PWA already installed.
event.preventDefault();
return false;
} else {
// PWA not installed.
}
});
function isStandalone() {
// Check if device supports service workers
if (!('serviceWorker' in window.navigator)) return false;
// Check for Android
if (window.matchMedia('(display-mode: standalone)').matches) return true;
// Check for iOS
if (window.navigator["standalone"] == true) return true;
return false;
}

Is it really posible to close a PhoneGap App?

I have searched all over the web and found different ways of closing a PhoneGap App. I tested all of them and none work. At least on Android.
Question:
Is it possible (By Feb 2014) to have a close button in a PhoneGap App on Android?
Thanks
This doesn't work:
function CloseApp() {
if (confirm('Close this App?')){
if (navigator.app) {
navigator.app.exitApp();
}else if (navigator.device) {
navigator.device.exitApp();
}
}
}
Is
navigator.app.exitApp()
really killing/closing the android app with phonegap?
I use cordova and have the same issue. Above mentioned code is just putting the app into background - I checked the running tasks (android task manager) after above code got executed by the app.
I am confused on why you want a button to close the app. Android already has a back button when clicked enough times will take the user back to the phone's main screen. There is also a home button that takes the user out of an app. Once, out of the app the user can "kill" the app through a task manager.
navigator.app.exitApp()
works and I use it in all my cordova apps. Check the rest of your code.
As ejwill said, having a "close" button is a bad idea. On Android I call exitApp when the user is the home page of my app and he presses the backbutton:
function onDeviceReady() {
document.addEventListener("backbutton", onBackKey, false);
}
function onBackKey( event ) {
var l = window.location.toString();
var parts = l.split('#/'); // this works only if you are using angularjs
var page = parts[1];
if (page == 'home') {
navigator.app.exitApp();
} else {
// do something else... one option is:
navigator.app.backHistory();
}
}
My 2c.

Unusual behaviour with changePage on android 2.3.6

I am building a phonegap app with jquery mobile and using build.phonegap.com
I have an event to change the page to the login screen after startup process have completed.
This works fine but it will not work on my andriod device unless a debugger is attached to it, in which case it works fine.
The code I have is
$.mobile.changePage("login.html");
I have put this in the mobileinit, pageshow, and now on document.ready function but it doesnt change the behaviour.
I've checked if $.mobile is a function and it is, Have tried everything and can not seem to figure out why this would be happening, any feedback would be much appreciated
I managed to put in a hack to work around this issue.
It was something to do with my phone being really old and slow, so something was getting a little messed up on old/slow andriod versions.
To prevent this from being an Issue I figured out this way that solves the issue and boots up my jquery mobile app on phone gap even if the phone is very slow.
$(document).bind('mobileinit', function () {
setTimeout(function () {
var html = $(".loading-status-text").html();
/* The html has Please Wait in the dom so we know it han't been touched by jQuery */
if (html == 'Please Wait') {
window.location.href = 'index.html';
}
}, 10000);
$(document).on("pageshow", function (e) {
var pageId = $.mobile.activePage.attr('id').toString();
if (pageId == 'loadingScreen') {
/* This wouldn't fire at first */
$(".loading-status-text").html("Welcome to Appname");
$.mobile.changePage("login.html");
}
});
});

Disabling 'go' button form submission in Android

I have almost completed an ASP.NET webforms website using jQuery Mobile. I am stuck on one specific use case.
The site is scoped to support Android, iPhone, BlackBerry and Windows Mobile all of the functionality works great except for one specific use case.
The case is when a user is entering a value into one of the input boxes and then hits the native Go/Enter key. I am capturing this and throwing the appropriate event submit button click/tap with jquery.
function BindSubmit(textbox, button) {
$(textbox).unbind().keypress(function (event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13) {
$(button).trigger('tap');
}
});
}
This works great on all devices but one, Android. The phone ends up submitting the entire form instead of following the use case. Grabbing the onsubmit event and returning false doesn't work either. After some digging I found this Disabling 'go' button form submission in Android when using webview .
I am hoping for a solution to this for a standard webform. Thanks.
Thank you for the help. The way we solved this is binding to the form.submit event and calling the mobile.changePage() ourselves. Then after the changePage() we return false; This prevented the full form submit and still allowed jquery mobile to complete its actions.
Try running $(button).trigger('click'). This might be a better, more cross-platform way of sending the event.
You should definitely try to test it like this on an Android phone and find out when and where execution fails:
function BindSubmit(textbox, button) {
console.log("BindSubmit()");
$(textbox).unbind().keypress(function(event) {
var keyCode = ...;
console.log("Key pressed: " + keyCode + ", isEnter: " + keyCode == 13);
if (keyCode == 13) {
console.log("Enter key hit, triggering event.");
...;
}
});
}
If you have a link to it, I'd be happy to test it on my Nexus One for you :)

Categories

Resources