I have an android application which consists of three activities:
LoginActivity
MapActivity
RegisterActivty
The Application starts with the LoginActivity and from there the app can open the RegisterActivty or the MapActivty.
Now suppose that from the LoginActivity the app opens the RegisterActivity and the user exits the app by pressing the home button.
Then, when I start my app again, it opens the RegisterActivty, that's good; but when I go from the LoginActicty to the MapActivity and do the same, I don't get the MapActivty - instead the app goes back to launching the LoginActivity.
How do I make my app remember what Activity was open last time it was used?
remove android:noHistory="true" from android manifest for the map activity.
Related
I have two apps, click the button in app A will jump to app B due to deeplink. And in app B, there are two activities including SplashActivity and MainActivity, where I set the intent filter in SplashActivity that deeplink will bring it to in app B when the button in app A is clicked. And it worked fine for most time.
However, here is the situation. I open app A, click the button, and jump to app B's SplashActivity, which start MainActivity in a while and then finish itself. Till now it works fine, however, when I switch front app to app A, which means app B is in background now, and then I click the button again in the app A. This time it doesn't jump to SplashActivity(onCreate() and onResume() of app B are not called), but to MainActivity by calling it's onResume() callback, and the intent.data, which is sent from app A, is find to be null.
So why the deeplink didn't bring the app to the expected activity in the situation above? Begging for any answer!
When opening the deeplink while app is in background, doesn't launch the new app instead it open the current instance of the app. This is to avoid multiple instances of the same app.
In the manifest file, you need to add the follow to your main activity.
android:launchMode="singleTask"
With this, if an instance of activity already exists at the top of the current task, no new instance will be created because it will fire off an onNewIntent() method instead of creating a new object.
You can fetch and handle your intent data in onNewIntent()
I am working on this Android Studio project, and after I'm making some checks in the Login activity, I want to be redirected to the MainActivity and finish the Login activity. However, after I login and I am being redirected to the MainActivity, if I press the back button, it will redirect me back to the Login Activity(the first time the login activity not being closed/finished). If I try to repeat the process and press back, this time works as desired, that is, it closes the app(the Login activity is closed/finished)
I checked my code a few times now, and I am not starting the same activity twice, so does anybody know why this happens and how to fix it?
Try to use finishAffinity() which closes the current activity and clears the stack. Then you will be left with MainActivity only.
More information: https://developer.android.com/reference/android/app/Activity#finishAffinity()
I'm following the next flow, Start activity A (loading resources), then go to Activity B (login). I marked Activity A as noHistory = "true" and just after I start the activity B I call finish() on activity A.
The app works as expected and when I pressed the back button from the Activity B the app closes, when I pressed the recents button and select my app, it restarts from activity A, I want it to starts from activity B.
thanks.
Add this to your activity declaration in the AndroidManifest:
android:excludeFromRecents="true"
And it will be excluded from the "recent apps" list
that is expected behaviour . Since you have pressed the back button the app is closed , if you launch from recent after that its like clicking on app icon to launch the app . You can use shared preferences to save if the first activity is already launched you can directly launch second activity
I have 3 activities ( say A, B, C were A-is the Launch activity). When I press home button when at activity C, app goes into background. After that, I took my app through all apps list menu. At that time, my launch activity is showing (activity A). When I press back button, It goes to previous activity (C). I want to retain in the same activity (C) while coming back from background. When I run application through Eclipse, It works fine. But when I send Apk file through mail and run it in device, It fails (previous problem occurs ).
I tried with
android:launchMode="standard"
AND
android:alwaysRetainTaskState="true"
in my launch activity (Login activity or A). Any body please help me, Thanks in advance.
Follow following steps to insure that you are following the right practice:
1. Make sure you are using finish(); on the Activity A or B if you want to finish it and dont if you want the back button functionality.
2. Try Implementing onpause() and onresume() even if you are not going to perform any functionality in them. Use super() for them there.
3. Also, in android when you start an activity by clicking on the icon instead of resuming it from already running activities, it exhibits a different behaviour.
I have three activities A->B->C.when i am in B activity i click the home button and put the application to back ground(B->home).
When clicking on the my application icon in the home screen the Activity A is opened not activity B .but upon long pressing the home key,its showing that my app is running in background and clicking the icon open the Activity B as expected.
What was the problem?i didn't handle any home key event.How to prevent relaunching my application.
When you make a long press the dialog shows recently used app and not the ones ruuning at the moment. To make sure your activity is not killed go toSettings-> Applications-> Manage Applications -> Running tab.
Usually the behavior you described is cause by launchMode attribute in the manifest.
Check that you do not have anything there.
read more about "launchMode" attribute here.