Android activity restart and Preference screen - android

I have an application with a MainActivity and few other activites. From the MainActivity I start a preference screen, where I set theme for my application.
MainActivity-> Settings->Choose Theme
Currently how it works:
I restart the application, start my Main activity and theme is applied to all the activites.
How I want it to work:
I want to restart the application and go back to the same screen where I set my Theme and not my MainActivity.
Can anyone please suggest me some ways in which I can do it?
Thank you in advance
EDIT:
How I want it to work:
Restart the application -> Go back to the "Choose Theme" Screen (Where it is set) .
Then when I press back button -> Settings screen -> and when pressed back again to my MainActivity.

I don't know if this is the best way, but you can save in SharedPreferences the Last screen you were on (or if it's just for this case, a boolean to know if you're coming from a restart)
and each time when the application start on onCreate() of MainActivity check the key in SharedPreferences and go to your Themes activity accordingly

Related

Refreshing home launcher on home button press

I have a launcher application, which users can customise in different ways. But the changes do not reflect. I was thinking if i can detect a home button press and on that create my launcher activity again. But how do i achieve this?
Also, is there a better method for this?
Write the changes you want to make to the disk (such as SharedPreference) and reload them in the onResume function of your home screen activity. Don't do it in onCreate or they will only be loaded once.

Changing Activity screen when the app is not running

How can i change the screen of an activity when pressing any button on an android phone that takes one away from the running app.
I'm trying to get a blank screen to show up on the "recents" screen, instead of a snapshot of the app.
You can use this option and check if it helps you meet your need.
android:excludeFromRecents="true"
Add this to your activities in the application manifest if you do not want the app to be shown in the recent apps list. One drawback is that you would not be able to resume the app from the Recents list. Not sure if this is what you need.
The other way is to have a 'Blank Activity', which you start when your actual activity pauses. You can then finish the 'Blank Activity' on its Resume. This way, you will have your app shown on the Recents list, but with a blank screen.
You can call finish() for activity but that will kill activity. I think that will leave blank screen. Or destroy(). Try both respond with results.
you might want to change the onpause() or onclose() functions of your app. they are the last thing android execute before leaving,therefor you can change the aspect off your app just before you leave it
EDIT :
Maybe if you create PopupWindow and set it to full screen, and color black when exiting no preview would be shown, but app would still be running (idea of user DjDexter5GH) in the onpause() and onclose() functions. therefgor,when you leave,a black(or whatever you want) screen is pushed in front
you can then close it in the onrestart(is it called this?)

Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED|Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET

When these two flags are added(or set) to a new activity A, A becomes the top of task's back stack and is shown on the screen. Here HOME is pressed, and the screen shows home.
What I want: Then let's go to launcher and select the app's icon, the app comes alive again, the A is gone.
What I am confused: Then let's long press HOME and select the app, the app comes alive again, A is still THERE.
I want A disappeared, however from Launcher or from Recent. How can I make it?
I don't think there is any easy way to do this. You can either exclude your app from the Recent list or save a flag in activity A that if true call finish() in onCreate.

onResume is not called when I relaunch the app after home button pressed

So I have my main activity, and when you press a button it launches activity2. Once activity2 is launched I press the home button and it will trigger onPause at activity2 and then the desktop of the android device comes to top. Everything's ok.
The problem is: now I click the app icon and instead of coming to top activity2 (the last active), it comes my main activity. So onResume is not called on activity2, but on my main activity.
Isn't it supposed to be called onResume on activity2? How could I make it work?
If you launch an application from the home screen launcher, you are specifically launching the activity which that launcher icon corresponds to.
The behavior you are thinking about is more along the lines of what occurs when you re-enter by way of an activity which is in the back stack.
If you want the home screen launcher icon to put you back in whatever activity you were previously in when that is different from the activity that icon is linked to, you'll need to keep track of that and have your launcher activity transfer you there.
Just to be sure, didn't you override the onKeyDown method which is able to catch device buttons?
Remove the android: launchMode="singleTask" from your launcher activity in the manifest file.

Remove state maintenance of screens Android?

I am very new developer for Android application so please ignore if there is some technical mistakes in my question.
I have five screen (Home, SR-1, SR-2,SR-3,SR-4 ) in my Android application and I can switch any screen at give time.
When we are pressing device back button it will take we to the previous screen where I was lastly.
But whenever I am pressing Home it will take me to landing screen If in this state I am pressing device back button I will take me to previous view but I want to remove this state maintenance.
(i.e. : When I am coming to Home and I pressed back button It will exit from my application)
Thank you
for each activity: you can add in AndroidManifest.xml
<activity android:name="nameofActivity"
android:noHistory="true"></activity>
From android pressing back button should exit the app :
Immediately after you start a new activity, using startActivity, make sure you call finish() so that the current activity is not stacked behind the new one.

Categories

Resources