I have an applicaton, which need a pop up to be shown from a service for which I have started an activity with flag Intent.FLAG_ACTIVITY_NEW_TASK. It has two buttons A and B. After clik of both buttons I am finishing the activity.
But even after I finish this activity (pop up), when I select my activity from recent activities (If i long press home button), I am directed to the pop up activity. How do I go my application's main stack?
Related
So I have an App that switches between activities using the onClick() method. One click takes you from the main activity to activity 1-6. Upon clicking activity 1-6, it will take you back to the main activity. I need a method that will upon clicking the main activity 3 times, will take the user to another, custom, activity.
It's a simple process, but I haven't seen any questions like this here on stack overflow.
I am working on a tracking application that use another third party application such as google map.
Lets assume my application has 4 activities ( act1, act2 , act3 and act4 ).
on act3 activity i am calling google map application to calculate the distance and view the routing. But once i clicked on the back button of the tablet, or go back to the home page and clicked on the launched icon, the act1 is displaying instead of act3.
However, my application is still running on background.
So my question here how can i make the application is opened the last activity which is act3 in our example, when the back button is pressed or when the launched icon is clicked.
Thanks,
Store the name of the running activity into shared preferences in the onPause of every activity (if you're exiting by pressing home button) or in onBackPressed (if exiting an activity by pressing back button).
Then create a launcher activity which reads the shared preferences and launches the specific activity.
Lastly remove the launcher activity from the activity stack so that the app doesn't go back to it on pressing back button.
Let's say the user presses a button which causes another activity to get launched. Now the user is in another activity. What flag do I have to add to the intent, so that the user returns to my app when pressing the back button instead of navigating down the back stack of the started activity?
From the documentation, "activities on the backstack are never rearranged."
Android documentation Tasks and BackStack
You do not have to add anything to the intent. When you navigate out of you app and start another activity to complete a task, the new activity becomes kind of like an extension of your app. Pressing the back button takes you back to your app. Read This
I've got an app that launches another activity via startActivityForResult. Everything works great if the user exits the invoked Activity via back button, however if the user presses Home instead, the invoked Activity exits and onActivityResult never gets called.
Is this expected behavior or should this work?
Difference Between Pressing Home Button and Back Button.
By default, pressing the Back button finishes (destroys) the current activity and displays the previous activity to the user.
By Default , pressing the Home Button activity is stopped and moved to the background rather than being destroyed
More in Details - Read Navigating Away from an Activity with Back and Home buttons
I have an app that circles around the main activity (a main menu). In each other app there is an option menu item that directs to this activity.
At first, I always started a new main activity when this item was selected. Using the intent bundle, I did tell the main activity that some initializations I do on a fresh start were not necessary.
However, I didn't quite like the overall behavior. I stumbled upon android:launchMode="SingleTask" and this seemed to help: now I don't recreate my main menu activity all the time; also, if I press the "back" button I come back straight to the home screen. This feels quite nicely like a proper "main" menu.
My problem now is this: if I run another activity of my app, press home button and then reopen my app (e.g. using "last apps"), then I don't go back to the last activity, but to the main one. The other activity is destroyed.
Any ideas how I can implement the behavior of SingleTask without only being able to return to one activity?
If your other activities are declared normally with activity defaults in Android, then going back to your app should take you to the same activity where you left off (using the hardware home button)
However remember that the Android system kills applications when it requires system resources. So your app may have been killed when you went to the other application. Then when you get back to your app, the default launcher activity will be restarted, which is your Menu activity.
To get back to the main activity from any activity, do this:
public static void goHome(Context context) {
final Intent intent = new Intent(context, HomeActivity.class); //give name of your main activity class here
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
That will clear the activity stack and get you back to your main activity. As you declared singleTop, it will bring the existing main activity to the foreground. The flag Intent.FLAG_ACTIVITY_CLEAR_TOP will remove all activities in the stack on top of the main activity. (I am assuming you are within the same application).
Now, all your other activities only need to include a button whose click listener invokes the method goHome();
From your main activity, if you press the hardware back button, it should exit your app.
Why not call finish() on the activities that were created by the main activity? This way you return to the main activity, without creating a new one...
I think you should save the state of you activity before starting another activity, and then resume your activity whenever you come back on last activity.
see Activity Life cycle from Android
http://developer.android.com/guide/topics/fundamentals/activities.html