Hello I currently have an Activity A with a fragment inside that the user can interact with, the goal here is to simply "background" Activity A and fragment and allow the user to use the rest of the app normally with a floating button that when pressed the user will be taken back to Activity A and the UI will be restored the same as the user left it. I've looked into onSaveInstanceState but that only applies to when the system ends it or when screen rotation happens and not when the user presses the back button. So is it possible to save Activity A with the same UI and restore it at any given time?
Edit: I also have no way of accessing/modifying the fragment's components since it's coming from an SDK already.
Related
I am developing an application that user can minimize (hide) resumed activity (but not all the application) by pushing to a button and previous one will be showed. Then, in any activity, by pushing another button, user can see the minimized (hidden) activity again with it's state.
I'm trying two way of solving this problem.
1 - When activity will be minimized(hide), all it's view's state and attributes will be stored to database after then the activity will be finished.
2 - Hold all activities in a separate task(singleInstance) and when it will be minimized, just call movetTaskToBack function.
How should i do or is there another way?
Just set the visible state of the containing layout to View.GONE (with setVisibility(). This will hide all the Views on that Activity.
I've got an app with two screens, we can call them List and Details.
If an user is at Details and presses Home to minimize the app and then switches back I want to stay in the view and just restore, but if he presses Back I want to go back to List, I figure I can save a "Done"-button this way. But...what's the proper way to do this?
Currently I've overriden onPause and onSaveInstance but it seems they're both called in both cases.
I'm thinking about overriding onKeyDown instead, like he did; How to control Activity flow - Back button versus Home button, but that doesn't seem like a "nice" way to do it so I thought I'd check if anybody else has another idea.
Make two activities, for list and for details. When you will press the back key in the details activity it will finish and will show up the list activity.
I am implementing a dashboard plus action bar UI, like in the Twitter app:
Each button on the dashboard takes the user to a different activity. A few of these activities are more important than the others, and I could imagine the user switching between them via the dashboard reasonably often.
I feel like I have two options:
Keep an activity cycle going using intent flags, so that when the user goes back to the dashboard it just pushes the dashboard activity to the top of the stack. Then when the user returns to another activity, it pushes that one to the top of the stack. No activity would be destroyed until the OS does it to gain back memory, which would be fine.
Let the activities be destroyed when the user goes back to the dashboard, then recreated later.
Which option is better in terms of performance and best practices? I like option 1 but am not sure if I'm abusing the purpose of those intent flags. And if I do go with option 1, should I also override what the back button does so that finish() isn't called?
Personally I like the first option better. This way, you would easily remember the state of the other activities when the user returns to them.
For example, if in a child activity the user scrolls some list, then goes back to the dashboard, and then returns back to the child activity, the scroll position will be where he left it off.
Regarding memory, I don't think it's an issue. Let's take a tab component for example (which is a parallel navigation controller to your dashboard). With a tab control, all the child activities (the tab activities) are never destroyed as well.
If memory does become an issue, I would combine your two ideas. For the less important activities I would implement approach 2 (destroy them on back), and for the more important activities (where state is important for the user for example), I would implement approach 1.
I have an activity here.
I want to click a button and then hide the activity GUI.
That is, GUI is needed and you can hide it by clicking a "Hide App" button. How can i
implement this "Hide App"?
Somebody help! Thanks in advance!
To do what you want within the organizational model of android, your "program" should be written as a service, not an activity. You would then have a gui that is an activity and a client of your service, which can be started (made visible) and paused/stopped (hidden) as desired.
Presumably when your user clicks the hide application button, you're going to want to show something - at the very least a show button, so the user isn't stuck without input options!
So what you really have then is two views, one with the GUI hidden.
Two approaches I can see:
Hide app calls another activity with only the UI shown that you want. When the activity is finished, use Activity.finish() to return to the original activity with the GUI
Look at ViewAnimator and its subclasses (ViewFlipper and ViewSwitcher)
You could also just enable the screen lock. ;-)
That would automatically lock the screen (hide your app). And when the user unlocked the screen (using the UI and a gesture the user is already very familiar with) he would automatically get back into your app without you needing to do any extra coding.
The additional advantage of the screen lock is that it can be be password-protected, so if the user has his screen-lock already set to a password, instead of a slide bar -- he would just get the slide password thingy.
How do I go to previous screen from current screen in Android app? I know there is a back button on phone, but it takes me to beginning screen of my app and I want my buttons on app to work for going back to previous screen.
Back button indeed takes you to previously seen activity on screen, that launched the current one (not by means of back button). If back button takes you to beggining screen of your app means that navigation to your last activity was done from it. Try launching an activity from another one different from start activity.
What really can be problematic is ending application once at start activity by pressing back button and discovering the application switching to activity that lauched start activity (not by means of back button). In this case you should just call finish() inside onDestroy() listener method of your start activity.