Refreshing home launcher on home button press - android

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.

Related

Flutter Launcher: Go back to the HomeScreen when Home Button is pressed

I am trying to make a launcher using flutter. I have made multiple screens for doing specific tasks like HomeScreen. AppDrawerScreen and so on. The problem I am facing is whenever I go to say AppDrawerScreen and press on the Home Button, I am not redirected to the HomeScreen. How can I handle this scenario?
I've had the same problem. I guess the only solution is to listen to the Home button, and there go to the first screen. there is a plugin called hardware_buttons, and about the Back button you can use the WillPopScope() widget.
You can achieve this by adding WidgetsBindingObserver mixing to your StatefulWidget class.
And then you can invoke didChangeAppLifecycleState() method where you can listen to the AppLifeCycleState changes like :
inactive
paused
resume and soon
But in your case since you want to navigate to HomeScreen when Android Home Button is pressed so you need to check if AppLifeCycleState.inactive is true (which means you have pressed the Android Home Button and app is running in background) and there you can add your code to Navigate to HomeScreen.
Also you can refer to this documentation for more information.

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?)

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.

Handling back and home button differently

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.

Moving between android activities on button clicks

I am writing a android application where, on startup activity view, I have a button "DoIt". When user clicks "DoIt" button, I start another activity with different layout. On newly started activity, I have a button "Back" which should take me to the first activity. How to accomplish this. What code should I write on OnClick method of "Back" button. Also, I want the newly created activity to die after back button is pressed and application comes back to start-up activity.
In the new activity you can just call
this.finish();
to return to the previous activity. If you want a result from the child activity you have to launch it with startActivityForResult() and override onActivityResult in the parent. The hard back key should always go back to the parent activity by default.
Call finish() on your activity. Also, why are you making a button on screen for this? This is usually the job of the device's back button.
In my opinion, Android is really bad on such scenario. In Activity, it doesn't support multiple views. Consider the situation that users want to switch from these two views, or even several other views? I think in this case, iPhone is much much better.

Categories

Resources