Create go back button function like Angry Birds - android

I'm creating an app in which Go Back Button function like Angry Birds have, I've created popup window, it has close button and other buttons working.
To go back I use:
#Override
public void onBackPressed() {
// Write your code here
initiatePopupWindow();
super.onBackPressed();
}
I know about finish() code that do not go back to pervious Activity
this code is working when goback Button is pressed. Popup Window opens but instantly it go back to previous Activity.
My Question is : How can stay popup window when go back button is pressed and do not leave to previous activity like Angry Bird games has
When user pressed go back button it open the popup window and user have to select one option
i want to make something like that
looking for suggestions
thanks

Remove this line:
super.onBackPressed();
From:
#Override
public void onBackPressed() {
// Write your code here
initiatePopupWindow();
super.onBackPressed();
}

Related

Android phone built-in back button

I have an activity with two fragments, each fragment has a back button to the previous activity/fragment. Both the back buttons on the fragments work properly. However when i run the app on my android phone and i use the built-in back button to navigate to the previous activity, it displays a blank activity and then when i press the built-in back button again only then does it navigate to the previous activity. The problem is clearly the back burton than built in.Is there a way to solve this???
There is a method in the Activity called onBackPressed() which is called when the device back button is pressed. If you want to control what happens on back press just override it. To remove default onBackPressed action you need to remove the call to super.onBackPressed() and then you control what happens when back button is pressed.
#Override
public void onBackPressed() {
//super.onBackPressed();
// do something here
// or perhaps nothing at all
}

Back Button default code in android

I want to back to activity that calls get intent so when i use this code app crashes,
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
But when i pressed back button which is beside the home button, it goes to the before activity the n app won't crash. So i want to know the back button code.
Please help me
The above code works when there is no get intent.
#Override
public void onBackPressed(){
if(you wanto go back){
super.onBackPressed();
}else{
//if you dont want to go back
// do what you need hear....
}
}
onBackPressed();
where u can do the same action button as back button event

Disable SoftInput Keyboard from Closing OnBackPressed

Just wondering if it's possible to prevent the keyboard from closing when the back button is pressed.
AKA, jump to the previous activity on one tap of the back button.
You can override onBackPressed() so that if the keyboard is showing you just call finish() on your Activity:
#Override
public void onBackPressed()
{
boolean keyboardIsShowing = // determine if keyboard is showing somehow.
if (keyboardIsShowing )
{
finish();
}
else
{
super.onBackPressed();
}
}
I am not sure an exact way to know if a keyboard is showing, but this link can point you in the right way:
How to check visibility of software keyboard in Android?
On a side note, users probably don't expect the Activity to close when the back button is pressed, they probably expect the keyboard to close. I would carefully consider your use case before implementing something like this.

Close app when hitting back button on android

So my login Activity is the first screen you see. When you hit the back button, it exits the app, good. So I open up the app again. After logging in, I am now in my main Activity. How do I make it so when I hit the back button now, it exits the app rather than going back to the login Activity?
When you push the new activity, call finish() on the previous, otherwise it will remain on the stack, therefore appearing when you hit back and pop the current activity.
Hope that helps.
try this one
#Override
public void onBackPressed() {
super.onBackPressed();
finish();
}

How do I return to a calling activity if the user presses BACK?

My MAIN activity is spawning a child activity that contains a ListView. While this ListView is being populated (through an AsyncTask), an indeterminate progress bar is shown.
However, assuming that I am an impatient user and I press the BACK button, the progress bar is cancelled but I am left with a blank screen. I have to press BACK one more time to go back to the MAIN activity.
I would like the app to go back directly to the MAIN activity by pressing BACK only once. Can somebody point me in the right direction? I am thinking I should call finish() somewhere but I don't know where to put it. Thanks in advance!
Use setOnCancelListener() on Dialog (which ProgressDialog extends).
you should override "onBackPressed()"
it will call when the activity has detected the user's press of the back key.
#override
public void onBackPressed(){
this.startActivity(this,MainActivity.class);
}
this code will call the MainActivity when emulator/ipphone back button pressed...
you can try like this,place this code in your activities oncreate block.
findViewById(R.id.back).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});

Categories

Resources