PhoneGap Android back button needs to be pressed twice - javascript

When I navigate to a second page and try to go back using the default back button that every android device has, it seems as though the first time I tap it, nothing happens. I have to tap it a second time. Anyone have any idea why this happens?
I'm not sure what more information I need to provide. If you need more info please request specifically what you need and I will try to edit the question.
Edit: my main activity extends DroidGap and only has the one method
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
I think I'm narrowing down on the problem. On the second page, there are a list of anchor tags that perform a css animation when clicked.
This jsfiddle isn't doing the animation for whatever reason but here is the relevant markup, css and javascript
http://jsfiddle.net/7fdQu/

I am not sure what is going on in background but there is a definite for it ....
you can program the back button in Android there is a code for it. The phonegap fires a event "backbutton" in Android.
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown() {
window.location.href = 'URL';
}
Ref:
Should I use window.navigate or document.location in JavaScript?
http://docs.phonegap.com/en/1.0.0/phonegap_events_events.md.html#backbutton

Related

Install silverlight application on button click

I am looking for a solution to install Silver light application in to user system, if he click on (install button ) in web browser.
I know how to do Out of browser but here requirement is not right click and install , it needs to install from HTML5 web page button click event.
I know can achieve from Silver light button click but I want to achieve this from HTML5 button Click event
private void Button_Click(object sender, RoutedEventArgs e)
{
if (Application.Current.HasElevatedPermissions && System.Windows.Interop.ComAutomationFactory.IsAvailable)
{
string run = "\"%ProgramFiles%\\Microsoft Silverlight\\sllauncher.exe\" /emulate:Silverface.xap /origin:\"http://www.silverlight.net/content/samples/apps/facebookclient/ClientBin/Silverface.xap\" /overwrite";
dynamic cmd = ComAutomationFactory.CreateObject("WScript.Shell");
cmd.Run(run, 1, true);
}
}
Thanks,
ineffablep
If your silverligt application is loaded on page, you may call silverlight's install method from javascript.
Walkthrough: Calling Managed Code from JavaScript
I have found the answer , to handle this I need to use HTA File
http://www.silverlightshow.net/items/How-to-distribute-a-Silverlight-OOB-Application.aspx

How to prevent Android from closing web-application when backbutton is pressed?

I am developing a HTML5 web-application and compiling it with Cordova (phonegap) 1.7.
I want to override the Android backbutton so that I can call window.history.back() instead of closing the application (default Android). How can I prevent Android from killing the defaultactivity on back button pressed?
I get the "Back button pressed!!!!" in logcat, so the method is fired before the application is closed.
This is what I have so far:
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
document.addEventListener("backbutton", function(e) {
console.log("Back button pressed!!!!");
window.history.back();
}, false);
}
EDIT: I am willing to accept an answer explaining a way to simulate the window.history.back() directly from the DefaultActivity.java android class if that is possible!
I solved my own question by adding the code below to the DefaultActivity.java file to prevent the default android behavior, and keeping the JavaScript code as stated in the question:
#Override
public void onBackPressed() {
return;
}
I hope this helps someone in the future with the same problem!
I took this approach. I hooked the backbutton event as you have shown. I look to see if this is the first page or not and then ask the user if they want to exit the program or not. This depends on what you want your program to do depending on its state. I did not add the override as you have shown; I didnot seem to need it.
if ($.mobile.activePage.attr('id') === 'firstpage') {
// Prompt to confirm the exit
} else {
window.history.back();
}
If they want to exit you can call:
navigator.app.exitApp();
to close your program.
I imagine you still want to allow the user to exit your app. I don't tend to use apps that
do not allow an exit of some kind.
Hope this helps you out.
Never had to do that but, have you tried to return true ?
Like in the Java SDK, if you return True, the system will assume you have correctly catched the event and will no longer pass it to other event listeners.

Browser tab close detect in gwt

I am developing a gwt application and I am going to support only for ie7. Now I have a requirement to detect browser tab close event.I have tried Window.addWindowClosingHandler(...) . But this is getting fired when we click any url in the page or refresh. I just want to detect only browser close event. I dont want to capture any other event like browser refresh, url click. Is there any way to detect only that.
it should work
Window.addCloseHandler(new CloseHandler<Window>() {
#Override
public void onClose(CloseEvent<Window> event) {
Window.alert("bye bye beautiful");
}
});
[EDIT]
or maybe you search onBrowserEvent(); and detect which event user do
public void onBrowserEvent(Event event)
{
switch (DOM.eventGetType(event))
Event.onClick
Event.onPaste
Event.onLoad
JavaScript doesn't expose what caused the page to get closed, so GWT unfortunately cannot expose this information.
The underlying JavaScript event is the onbeforeunload event.
You could use session cookies, as described in the selected answer of this question:
GWT WindowClosingHandler firing on Browser refresh too

Capturing native button clicks in Android phone in javascript

Is there a way by which we can capture the click of HOME and BACK button in the html file in android application using phonegap/jqtouch/javascript?
I have an application for Android using phonegap. I want to capture the click of native HOME and BACK button of the Android phone in the html page to exit / go back gracefully.
You can catch the BACK button event in PhoneGap, however not the HOME button (this is a bad Android practice as there is a clear user expectation regardless of the app you're using about what the HOME key does: sends you back to your home screen! You don't want to override this functionality).
I will direct you to pieces of code in PhoneGap (LATEST source! pull from github for latest version of the phonegap framework) for guidance.
First, there is a 'BrowserKey' java object bound to the 'BackButton' JavaScript global:
http://github.com/phonegap/phonegap-android/blob/master/framework/src/com/phonegap/DroidGap.java#L291
The definition of this class is here: http://github.com/phonegap/phonegap-android/blob/master/framework/src/com/phonegap/BrowserKey.java
First thing you need to do in your application (I suggest you run this during application initialization) is to let the native side of the framework know you are overriding BACK button functionality. You would do this in JavaScript with a simple call:
BackButton.override();
From there on out, you can attach an event handler to the document's 'backKeyDown' event to execute logic every time the BACK button is hit. Something like this should work:
document.addEventListener('backKeyDown', function(e) {
alert('you hit the back key!');
}, false);
As an addendum, here is the JavaScript code that wraps the back button event dispatching: http://github.com/phonegap/phonegap-android/blob/master/framework/assets/js/keyevent.js
Basically, after calling BackButton.override(), the native side of the framework will call window.keyEvent.backTrigger() every time the BACK button is hit.
This code sample works for PhoneGap 0.9.5 and later (tested on 0.9.6) :
document.addEventListener("menubutton", function () {
alert('Menu button');
}, false);
document.addEventListener("searchbutton", function () {
alert('Search button');
}, false);
document.addEventListener("backbutton", function () {
alert('Back button');
}, false);
Home button can't be handled. That's reserved by the system.
I have an application for Android using phonegap. I want to capture the click of native HOME and BACK button of the Android phone in the html page to exit/go back gracefully.

Detect Idle Silverlight Application

What's the simplest way in Silverlight to detect the user is not active?
i.e. no mouse input and keyboard input for a period of time.
I tried monitoring the mouse events, keyboard events and the focus events of the root visual but it doesn't seem enough.
For example, a popup window may be open and these events won't reach the root visual.
Maybe javascript solution?
And then comes the other problem. When the application is idle I would like it to appear gray (just like ChildWindow behavior). And I would like it to appear like this even if there is an open ChildWindow or a simple Popup at the moment.
Are you sure the child window doesn't bubble? It is a routed event ... didn't realize that.
If not, just create a contract like:
ILastActivity : INotifyPropertyChanged
void Touch();
DateTime LastActivity { get; private set; }
Then you could create an attached behavior, a base class, or use any other mechanism to simply register the key events on your views. They all would call "Touch" when fired, and your timer would inspect LastActivity to determine it. Might be something you can do with automation peers as well, worth looking into.

Categories

Resources