Back button event is not fired after soft keyboard hide event - android

I am developing an application, where there is a log-in page and I have included
document.addEventListener("backbutton", handleBackButton, false);
function handleBackButton() {
}
to handle back button event which works perfectly fine, but when I click on any input field softkeyboard is shown up and on pressing the back back button the key board gets down but when I click again on the back button the app crashes instead of calling the "handle backbutton" function

try this
#Override
public void onBackPressed() {
super.onBackPressed();
this.handleBackButton();
}

Related

Which Accessibililty event will get trigger when click back, home, menu buttons in android

i tried to open the app and some accessibility events got triggered but when i click back or home or menu button in android devices i can't get any accessibility event. is this possible to get some event when clicking button. if it is normal apps i can get the clicks of a back or menu or home buttons click using on Pause method. how can i get for Accessibility service class. please anyone can help me.
you can override onGesture(int gestureId) method in your Accessibility Service class to get the key events such as home event, back button event..
#Override
protected boolean onGesture(int gestureId) {
if(gestureId == GLOBAL_ACTION_HOME) {
Log.d(TAG, "Gesture Home Pressed");
}
return super.onGesture(gestureId);
}
For Reference: https://developer.android.com/reference/android/accessibilityservice/AccessibilityService.html

Android 'complete action using' back button press handling

My android app uses
Intent i = new Intent(Intent.ACTION_VIEW, uri);
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i);
to begin the twitter OAuth process. This code is triggered by a button press. I would like the button to change to a progress bar when it is pressed, which I have implemented.
When the new activity is started, the user is prompted with a 'complete action using' dialog, and if the user presses the back key while this dialog box is showing, they are returned to my activity. I would like to handle this event and turn my progress bar back to a button - how can I do this?
When the user clicks back, the onResume() method of the fragment is called. Because of this, I can change the button back to the normal style.
You can override the method onBackPressed(). Inside it, you can do what you want, so when you press the back button it will be trigered.
An example for your case would be to put this code on your activity:
#Override
public void onBackPressed()
{
super.onBackPressed(); // this will do the normal behavior of the back pressed.
//in this case, it will close the dialog
button.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
}
I hope it helps =)

Phonegap : Back button not working

I have disabled the back button in menu.html page. Using this
i have successfully quit my app on pressing back button on phone.
But this causes back button not working on any other page.
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false); //Listen to the User clicking on the back button
}
I want to navigate to Menu.html page when cliked on back button on phone. I have tried this but failed.
function onBackKeyDown(e) {
e.preventDefault();
navigator.notification.confirm("Are you sure you want to go to Menu page?", onConfirm, "Confirmation", "Yes,No");
// Prompt the user with the choice
}
function onConfirm(button) {
if(button==2){//If User selected No, then we just do nothing
return;
}else{
window.loacation="menu.html";// Otherwise navigate to Menu Page
}
}
how can i link to menu page when cliked on back button?
try to use window.location.replace("menu.html")

Android: how to simulate back button to hide a keyboard?

This problem may seem trivial but I wasn't able to find any nice and simple solution.
I've got an activity with a EditText and a software 'back' Button which simply calls finish() method of activity.
When I click on the EditText, there is a soft keyboard shown to input the text.
I want to achieve the following functionality when clicking the 'back' button (exactly the same as it is with the hardware back button):
- when the Keyboard is hidden, the onClick method should call finish() to end the activity
- when the Keyboard is shown, the onClick methond should hide the keyboard.
Is there any simple way to do that?
Keyboard Pasition
finding if keyboard is hidden or not?
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Selection of Back Button
1)First you have to detect the back key in functionality :
here is code:
start changing the ‘Back’ button, behavior, you need to override the onKeyDown()
method and than check if the desired button has been pressed:
//Override the onKeyDown method
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
//replaces the default 'Back' button action
if(keyCode==KeyEvent.KEYCODE_BACK)
{
//do whatever you want the 'Back' button to do
//as an example the 'Back' button is set to start a new Activity named 'NewActivity'
this.startActivity(new Intent(YourActivity.this,NewActivity.class));
}
return true;
}
at least for Android 2.0.
#Override
public void onBackPressed()
{
//do whatever you want the 'Back' button to do
//as an example the 'Back' button is set to start a new Activity named 'NewActivity'
this.startActivity(new Intent(YourActivity.this,NewActivity.class));
return;
}

Disabling the back button with an alertbox?

I have an alert box for a log in and when ever the back button is pressed the alert box disappears. I've tried #Override
public void onBackPressed() {
// do nothing.
} but it still just stops the back on the activity not the alertbox. Is there something special i have to do to disable the back button on the alertbox?
I believe setCancelable() is intended for this...
http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setCancelable(boolean)

Categories

Resources