How to get Android to always open root Activity - Android Software Development

Ok, so I have been struggling for a couple days with this, and I hope someone can help me.
I want Android to always run my splash screen activity, because I load a bunch of data from web services that I need throughout the rest of the app. This works fine with the flag android:clearTaskOnLaunch="true" set when you launch the app from the home screen.
Where it does not work so well is the long press of the home button and then selecting the app. In that case it starts the app in whatever random spot the user left it last. The problem is that if the app has been killed due to memory, it still shows in that recent apps list and when a user restarts the activity from the long press, all my data is gone so the app force closes.
So, my ugly workaround is to remove the app from the recently run list. I would much rather it showed up there but that it started my app the same way as if it was clicked on the home screen.
Anybody know how to do this? The ebay app pretty much does this, so I know it can be done.
-frank

Instead of reading your data in OnCreate, you could do it in OnResume. See the flow chart here:
http://developer.android.com/reference/android/app/Activity.html
as you can see, OnResume is always called whether the app is created initially, resumed from pause, or reloaded.

kaediil said:
Ok, so I have been struggling for a couple days with this, and I hope someone can help me.
I want Android to always run my splash screen activity, because I load a bunch of data from web services that I need throughout the rest of the app. This works fine with the flag android:clearTaskOnLaunch="true" set when you launch the app from the home screen.
Where it does not work so well is the long press of the home button and then selecting the app. In that case it starts the app in whatever random spot the user left it last. The problem is that if the app has been killed due to memory, it still shows in that recent apps list and when a user restarts the activity from the long press, all my data is gone so the app force closes.
So, my ugly workaround is to remove the app from the recently run list. I would much rather it showed up there but that it started my app the same way as if it was clicked on the home screen.
Anybody know how to do this? The ebay app pretty much does this, so I know it can be done.
-frank
Click to expand...
Click to collapse
In the onResume for the activity that is crashing, you could test your data to see if it's still there, if it's null you can run the code to repopulate it again.

Related

automatically cloasing apps when exiting (like treo's palm)

Is there an app that can close selected apps when they are not being used, one thing I don't like is apps running in the background the having to go to the app just to close it with magic button or the right hard key.
on the treo apps close as soon as they are not on the screen.
thank you
Download this freeware...
http://www.freewareppc.com/utilities/inclosemobileexpressedition.shtml
whats wrong with magic button? it closes apps rarather minimise when you press top right button and you can close all runnings apps with ease. what else do you want it do do?
that said, i am actually looking for an alternative myself. although i love it, i do find that it tends to crash out pretty often. i am constantly restarting it. anyone else finding this?
i find that magic button will work fine until... you show the phone screen. it can't seem to close it correctly. it flicks it on an off several times and generally goes bonkers.
For a very minimal look, try VJOkButt.
V

All messages> Back switches apps instead

I noticed a bug that allows you to switch to running apps that were left behind with the home button.
Prerequisites: HTC Messages widget on one of the main screens.
Steps to reproduce:
1. Open an application (like 'people') and exit out with the home button, not the back button.
2. Repeat step one if you want to add other apps.
3. Go to the HTC messages widget and tap it to open a message.
4. Select menu option "All messages".
5. Press the 'back' button. This will switch to another app instead of close the messages.
6. Repeat step 5 to close the app and move to the next one.
Further notes:
Some apps will continue to show up even if you press 'back' on them to exit out.
For example, "People", "System settings" and browser never closes. Camera app does close, but you have to leave it by pressing 'home'.
Works on generic 1.5.
android dosent close apps untill needed lol just hold the home button to open any program you have run recently lol
mancsoulja said:
android dosent close apps untill needed lol just hold the home button to open any program you have run recently lol
Click to expand...
Click to collapse
I didn't know that - it is not mentioned in the manual. Thanks for that useful tip. Looks like a useful shortcut back to where you were before.
But how do you close a programme rather than let it waste memory and battery in the background?
peterc10 said:
I didn't know that - it is not mentioned in the manual. Thanks for that useful tip. Looks like a useful shortcut back to where you were before.
But how do you close a programme rather than let it waste memory and battery in the background?
Click to expand...
Click to collapse
If android needs ram it will close apps as needed but you can always download a task manager from the marketplace, there are some good free ones, i suggest advanced task manager its what i use
It would be good to be able to actually get them to exit properly.
Especially so when you have 4 or 5 "All messages" apps that won't go.
The only use this bug has is to take you to apps that are actually running as opposed to your history.
It also takes you to screens that a task switcher can't do for you, like the last screen you see from your last phone call and the call history.
frankv100 said:
The only use this bug has is to take you to apps that are actually running as opposed to your history.
Click to expand...
Click to collapse
I don't see this as being a bug. The ability to be able to short cut to the 6 (I notice it is limited to 6) previously used apps by a long press on the home button is obviously something the designers have deliberately included. And to me it is a useful additional feature (now I have found it!).
It seems to be history rather than running apps you are looking at - I closed several of my running apps using Astro and yet they still subsequently appeared in the list.

[Q] Disable Home Button for toddler app?

I've developed and app that is a slide show of pictures which each play a sound when you tap them. It's like a picture book for ages 2-4.
The problem is, since android won't let you capture a home button press and essentially disable it, when parents give the phone to their child to play with unattended (brave parent), the child can inadvertenly exit the app and then make calls or otherwise tweak the phone.
There are two other apps that currently have a psuedo fix for this issue. The apps are Toddler Lock and ToddlePhone. I've tried contacting the developers of these apps for some guidance but they haven't been willing to disclose anything, which if fine, but does anyone here have any suggestions?
It looks like both of those other apps are acting like a home screen replacement app. When you enable the "childproof mode" on those apps the user is prompted to chose and app for the action and the choices are "Launcher, LauncherPro, etc." plus the toddler app. You then have to make the toddler app the default and voila, the phone is "locked" and can only be "unlocked" using a key combination or touching the four corners of the screen, etc. when you "unlock" the phone. your normal home screen app default restored. You don't even have to make the toddler app the default the next time you enable the "childproof mode".
I have read that these two apps have problems with Samsung phones and they can cause an an infinite crash-and-restart-loop that requires a factory reset to fix. Obviously this is not the ideal solution to the problem but it looks like the only one availiable at this point.
Does anyone have any ideas on how to implement a "childproof mode"?
Could it run on top of the lock screen
So Do you mean making the app a lock screen replacement? I suppose that could work.
Do you have a suggestion on how to accomplish that?

[Q] Task not resuming to last activity when launched from home screen

My android application has a login screen that is launched as the main activity with intents as follows:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>​
Nothing else is out of the ordinary (that I am aware of, concerning the other activities, etc, no additional intents set on those or anything).
With the emulator, if I login and the second activity is launched, then I press the home button, if I launch the app again from a homescreen shortcut the task returns to the second activity. This is the desired behavior, as I don't want the user to have to login over and over again.
With both an HTC Incredible and a Droid X (only phones I have access to), if I login and the second activity launches, then press the home button, if I relaunch the app from a homescreen shortcut, it always launches the login activity, which is not the desired result. I want it to resume at the second activity where I left off.
I do have a task killer on the two phones I tested with, but they are set to not automatically kill any tasks and I don't believe this is happening because when I launch the app again for the second time and it shows the login screen, if I click "back" from there, it goes back to the activity I was hoping it would resume to, so the activity stack seems intact.
Does anyone have any insight as to why this works as intended with the emulator but not on the phones? Thank you very much.
I posted this on stackoverflow as well, but since I am new to this forum I could not include the link.
Note
I also just discovered that if I resume the app by holding the home screen button down and choosing the app from the recently used list that pops up, that it resumes to the last activity I was on properly. So it seems to just be from the app launcher shortcut or a home screen shortcut.
You can override that by setting android:alwaysRetainTaskState to True in the root activity.
http://developer.android.com/intl/fr/guide/topics/manifest/activity-element.html#always
This attribute must be on the root activity, so if your root activity is only the login activity and not the primary activity you want the user to return to, then you will have to do something a bit more complex. You will either need to make the login forum be a view on the primary activity, or make the login activity store the information and re-launch primary activity (not recommended).
You might also want to look at android:launchMode="SingleTask"
The above will solve the issue you are having, but the best solution by far is to instead use a long running service to handle the connection and login state, and make your activities just use and configure the service (login creates and sets up the service, primary activity acts as a proxy to the service commands, and logout shuts down the service). This will also prevent the login from being lost if memory gets low enough to shut down an activity, but not low enough to require a service shutdown.
I was able to get it working, thank you RoboPhred. The funny thing though, is nothing extra was required.
I think what was happening was that the old shortcut I had on my home screen was just that, an old shortcut. It was most likely botching something up. Once I uninstalled the app and created a new icon on the home screen, all is working fine.
Most likely this is why it was fine in the emulator as it fully installs the new apk.
So other devs be aware that old shortcuts may have some iffy intents depending on old builds etc and when in doubt fully uninstall the app and create new shortcuts.
I just wanted to thank you once again for at least replying with a potential fix, as it got me testing it again.
Thank you very much.

WP 8 and Multitasking

Hello there!
I would like to try it by myself, but unfortunately I cant. So, someone who tried the SDK, have you noticed changes in multitasking system?
Right now the only way to resume an app is using fast app switch. But I really dont like it. I rather just use the homescreen icon instead. Right now it relaunch the app.
Any changes on that? (oh please)
Thank you so much!
mikeeam said:
Hello there!
I would like to try it by myself, but unfortunately I cant. So, someone who tried the SDK, have you noticed changes in multitasking system?
Right now the only way to resume an app is using fast app switch. But I really dont like it. I rather just use the homescreen icon instead. Right now it relaunch the app.
Any changes on that? (oh please)
Thank you so much!
Click to expand...
Click to collapse
Windows Phone apps can never resume via the homescreen like iOS, due to the addition of the hardware OS back button.
To illustrate why; imagine you have an app that has start page and a settings menu. When a user goes to the settings menu, they can only go back to the start page by pressing the hardware back button (this is standard Metro design).
Now imagine a user opens the app, goes to the settings menu, then exists the app by pressing the Home button. They then do a few other tasks and then resume the app. They are now stuck in the settings menu and can't get back to the app start page; the back key will take them back to the WP8 Home screen (this is how the WP OS backstack works).
To get around this issue, Microsoft specify that starting the app from the front page always has to start a fresh instance, so the user can never get "stuck".
iOS has software back buttons on every page, so all apps can resume however you launch them. Android had the same problem with their back button (actually worse, as their backstack can be altered by the OS choosing to kill memory-intensive apps); to get around this, from ICS onwards Android apps are meant to have a software back button in the top-left, to go back within the application (hardware back key is still OS backstack).
Aphasaic2002 said:
Windows Phone apps can never resume via the homescreen like iOS, due to the addition of the hardware OS back button.
To illustrate why; imagine you have an app that has start page and a settings menu. When a user goes to the settings menu, they can only go back to the start page by pressing the hardware back button (this is standard Metro design).
Now imagine a user opens the app, goes to the settings menu, then exists the app by pressing the Home button. They then do a few other tasks and then resume the app. They are now stuck in the settings menu and can't get back to the app start page; the back key will take them back to the WP8 Home screen (this is how the WP OS backstack works).
To get around this issue, Microsoft specify that starting the app from the front page always has to start a fresh instance, so the user can never get "stuck".
iOS has software back buttons on every page, so all apps can resume however you launch them. Android had the same problem with their back button (actually worse, as their backstack can be altered by the OS choosing to kill memory-intensive apps); to get around this, from ICS onwards Android apps are meant to have a software back button in the top-left, to go back within the application (hardware back key is still OS backstack).
Click to expand...
Click to collapse
But it sucks so bad! They should review this. I hate to use the back button, and I hate to not resume the app. Using a common app, for example, WhatsApp. I was in a chat with someone. Then I hit Windows button and Im at start screen. Then I receive a message from the same person I just left the chat. What I do? I can open from the toast, can open from fast app switch (back button), or open from start screen icon.
If I open from toast, that will depend on what the app was meant to be. In WhatsApp it would take me to the chat, because of deep toast notification. But, right now, it needs to reload the whole app to open just the chat.
If I open from fast switch, it will resume the app right away. Nice. But in any other platform the message would be there waiting for you. Right now, in WP, it takes a lot to refresh the chat. You keep like 10 seconds staring at the screen waiting it. Its even faster to just reopen the whole app.
And if I open from start screen, its almost the same effect of toast, but it dont take me to the chat, but to the start screen of the app.
The point is, the fast switch is not helping that much. In fact, it would makes sense to change the fast switch to open when holding the Windows button instead of back button, and whenever an app is open, opening it from start screen icon just resume it. Actually, a lot of people doesnt even know, or even knowing, doesnt even use fast switch. Im not a common smartphone user, and even so I dont use fast switch.
For me, its the worse problem of platform. And I dont care about CE or NT if it works, but I care about it working at all. Doesnt make sense to put a whole computer in my pocket if it cant resume a single app.
i don't like the idea either to relaunch the app when you just have put it in background. then again, i also hope we will be able to close apps from the fast-appswitch-screen. and add an option to the gesture lovers out there: pinch out on homescreen to launch multitasking. or swipe from edge like w8. or anything like that. it would add to UI experience and would eliminate that 2-seconds-pause when pressing and holding down the backbutton.
Was the question not about Windows Phone 8?
Windows Phone 8 is supposed to behave differently, since true background processing is supposed to be enabled. I haven't played with the SDK yet, but I suspect that for non recompiled apps, things will behave as they do on Mango. But, I think that things changed to target WinRT and set to be able to run in the background will be able to resume right where you left off.
It wouldn't make sense for an app that is running and processing things in the background to restart when the tile is pressed.
It's been a while since I used Mango or wrote any apps for it. But, when an app is suspended, the dev has a specified amount of time to save the state.
That way when it is relaunched, the app can resume where it left off, by processing the saved state on launch. I thought with fast resume the app stayed in memory, but that was done through a registry hack and not directly made available by any carrier.
After doing some reading, the multi tasking enhancements might only add gps and voip to the currently supported background processing.
JVH3 said:
But it sucks so bad! They should review this. I hate to use the back button, and I hate to not resume the app. Using a common app, for example, WhatsApp. I was in a chat with someone. Then I hit Windows button and Im at start screen. Then I receive a message from the same person I just left the chat. What I do? I can open from the toast, can open from fast app switch (back button), or open from start screen icon.
If I open from toast, that will depend on what the app was meant to be. In WhatsApp it would take me to the chat, because of deep toast notification. But, right now, it needs to reload the whole app to open just the chat.
Click to expand...
Click to collapse
Tapping the toast to re-open the chat is the correct behavior here. I guess it's just bad coding that makes it take so long to resume; it should just be able to go straight to the conversation and skip all the "loading contacts...connecting" stuff.
JVH3 said:
Was the question not about Windows Phone 8?
Windows Phone 8 is supposed to behave differently, since true background processing is supposed to be enabled. I haven't played with the SDK yet, but I suspect that for non recompiled apps, things will behave as they do on Mango.
But, I think that things changed to target WinRT and set to be able to run in the background will be able to resume right where you left off.
Click to expand...
Click to collapse
Are you sure you're not thinking of Windows 8? For Windows Phone 8, no changes have been announced regarding multitasking or background tasks, *except* that a few select APIs (VOIP, location) will be able to run in the background, similar to iOS (not true backgrounding like Android)
Also we are talking about resuming, not background processing. In the WP8 SDK emulator, apps built into the OS don't resume; Therefore it's safe to assume 3rd party apps are not going to either.
JVH3 said:
It wouldn't make sense for an app that is running and processing things in the background to restart when the tile is pressed.
It's been a while since I used Mango or wrote any apps for it. But, when an app is suspended, the dev has a specified amount of time to save the state.
That way when it is relaunched, the app can resume where it left off, by processing the saved state on launch. I thought with fast resume the app stayed in memory, but that was done through a registry hack and not directly made available by any carrier.
Click to expand...
Click to collapse
When an app is closed the developer is meant to save the state, so that it can be reloaded if it is quick-resumed. However, once the app leaves the backstack (the 5 apps that appear in when you hold the back-button), this state is supposed to be discarded.
This is not a technical issue; it would be trivial for app developers to save the state and make their apps resume. The issue is that Microsoft's publishing guidelines (to get your app published on the WP app store) specifically says that an app launched from the home screen must launch showing it's introduction page, i.e. it can't resume. It could save some state, so a web-browser could still have all the recent tabs open, but it couldn't show the last one seen (ironically IE9 does resume it's state - guess Microsoft are allowed to break their own guidelines).
I agree it doesn't make sense to restart an app that is performing some background task; but then how to you avoid users getting stuck within a certain page, as in my example above? If WP8 includes a hardware back button, they can't change this policy.
Well, thats a shame. I hate reloading the app everytime I need it. Its so meaningless. I dont need VOIP, I dont need Skype running all the time. But I do need apps to be fast.
It really depends on how exactly the developers save their app state when the app is sent to background/tombstoned.
I, for one, use a text file to save data ( a lot of data) and proceed to loading the app as usual, and the moment the user presses a button, a pop up asks him weather he wants to restore or start anew.
I'm guessing that not every app will do this, as it is up to the developer to implement this.

Categories

Resources