I am developing my first app now and I see that whenever I click on a new activity it opens up and everything is fine. I can also go back to the main activity and then open a different and it all works.
However once I open the task switcher, all the previous activities show up. They all show up as seperate apps and if I click on one of them that is not the main activity I cannot go back the to the main activity its like its very own up with just that activity.
This is very strange. Does this have to do with how I implement the onDestory method? Because to be quite frank I never used it.
Please help me!
Thank you!
Related
I got a little problem with my app and I hope you could help me.
I developed an android app which contains an activity with fragment container which by default contains a pageviewer and through a navigation bar you can populate some more fragments.
In each of the fragments there are items, and when you click them they start a new activity.
Everything is working great until I drive my app into a state that the android OS kills its process for other apps, as described in the picture :
After I return to the app the listview is working fine, however when I click an item the new activity doesnt start, and the application just stays on the same page and for some reason OnResume() is called.
I check with debug messages and the OnClick function is working and the intent looks exactly like before the process kill.
Moreover, if I navigate to a new fragment everything is working fine.
Hope someone has the answer,
Thanks
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 am developing a small application at the moment it consists on 3 Activities.
Now when I start my application it starts fine and I can navigate from activity1 to activity 3 properly and without any problem.
Activity1-->Activity2--->Activity3
The problem comes that when I press the back button of my mobile device to go back to activity2, the application simply closes.
Can somebody please suggest how to figure it out what is happening.
that is how i am going to Activity2 from Activity2
Intent activity3 = new Intent(Activity2.this,Activity3.class);
Activity2.this.startActivity(activity3);
Activity2.this.finish();
Note:I am not using emulator I am using mobile and doing all the debugging directly on the mobile.
Thanks
This is because you are calling the finish() function which removes the activity from the stack. Remove the line Activity2.this.finish(); and you should be going back the way you wanted.
Because you call finish() method.
Due to this from activity stack your last activity is removed so that's way your current activity is finished on backPressed().
To overcome this You must remove
Activity2.this.finish();
from your code.
I have an application with a Main Menu to access several options. One of these options is the main option (List Tasks). This application has a log in system that works with accounts.
I want to have something like WhatsApp. In WhatsApp, when you click on a notification the conversation is shown, and when you close that conversation the activity with all your conversations is shown. I want that, when you open the application, the List Tasks activity is shown, and when you close this one you'll see the Main Menu. To do that I made MainMenuActivity to call TaskListActivity as soon as it's created.
This works fine when I open the application and I'm logged in, the user doesn't see that two activities are opened, it seems like TaskListActivity is the only one opened. But if I do it when I log in (from AccountAuthenticatorActivity), the MainMenuActivity is shown for half a sec and then the TaskListActivity is shown.
How can I fix it? I'm doing it the wrong way?
Do what you need to do in onCreate() (but do not call setContentView() - it'd be pointless), fire new intent to call another activity and then call finish() to kill your "transitional" activity at the end of its onCreate(); Voila ;)
The official Dev Guide of Tasks and Back Stack says, activities can be instantiated multiple times, and Home Activity is taken as an example
So I tried it out as the graph illustrates:
Launch Activity 2
Press Home button
Launch Activity 1
Press Back button (so I return to Home screen)
Press Back button again
But I did not go back to Activity 1. Thus, it seems that Home Activity has not been instantiated multiple times. Is it so? If so, how is it kept in a Back Stack?
EDIT: Sorry, I should've clarified earlier that I didn't write any codes to test it. All I've done is just launching applications on favorites tray. I'd better go to read the source code and search for the behavior of Home Activity.
Anyway, I don't think Home Activity is a good example here to illustrate multiple instances.
Your issue might be that you might have called finish() in your Activity2. Or, the OS clears up the 2nd Activity before you return back to it. The behavior you are trying to attain on your own has no guarantees. You can't force an Activity to keep running so that you can return back to it.