I have a splash screen that is an activity, after 2 seconds it will launch the login activity but the screen remains the same. If I change to home screen and go back to app, the screen updates to the login activity. This is happening recently, before I didn't see this issue. Also I haven't touched anything from the splash screen.
I'm using a Handler with postDelayed.
handler.postDelayed(runnable, 2000);
you are going to splash the screen to the next activity when you write the finish() because you don't want to again open this activity when the user press back press.
The same thing is the log-in screen when the user enters your login details in this time you enter the boolean value in the Sharepreference variable and also finish() login activity.
The next time the user opens the app splash screen will be visible when the splash screen visible you decide the activity through share preference variable data where you are going.
Related
I want to use my a custom splash screen whenever my app comes back from background and i want the splash to be displayed until all data from the app is loaded. so actually the splash will be working as a loader.
Currently I have implemented DefaultLifecyleObserver to my Main class and on its onStart() method I start a new activity which i am using as a splash. In splash activity onCreate method i am doing nothing but calling finish() method after 3 seconds.
so basically whenever app returns from background it redirects to splash screen and after showing that for 3 seconds it shows me where i left.
Problem with it is that when app loads from background it shows where i left for 1 second and then it redirects to splash instead of instantly redirecting me to splash.
i have tried using onRestart onResume methods it doesnt work with my requirements too.
I build an app. There are so many activities. When clicked on the back button of the phone it supposed to exit from the app when in the `MainActivity` but when clicked on back button it switches between the activities visited recently. I added Intents to switch to the activity I need to switch for every activity except `MainActivity`. Now they are working perfectly but I need my app to exit when clicked on the back button of the phone when in the `MainActivity` and also one thing, I have an **Splash Activity** in my app. I made some apps earlier also and there were one `WebView` app and there are only one Activity. In that app also there were a **Splash Activity** and when clicked on the back button it goes to the splash activity and not exiting the app. Also I need to exit the app when clicked on the button.
Please help me!
God Bless!
This can be achieved using finishAffinity()
I implemented an app intro which when first launched, takes the user through an introduction of the application.
This app intro only shows at the initial first launch of the application and ceases afterward. Is there a way I can implement my splashscreen to where the splashscreen will launch for subsequent launches?
Here're my recommendation:
Always start your Splash screen as main Activity.
In onResume() method of Splash screen, look for a boolean in your
SharedPreferences against a key (let say "isFirstLaunch")
indicating if the into has been shown before or not. If not, this is
your first launch.
Now immediately launch your Intro Activity if its first launch from
onResume() of Splash activity, and override Intro Activity's
onBackPressed() or onDestroy() or finish() or inside your
custom button click listener to save the boolean into
SharedPreferences indicating it has been shown.
For every other launch, continue your normal flow of Splash.
This way, managing from Splash screen is easy.
In my app I have a requirement that if the Home button is pressed during the working of app and if the user starts the app from the icon from home screen it must resume from the last activity.
How do I save the last screen history and resume it from the same screen?
The AlwaysRetainTaskState might be what you're looking for.
In your AndroidManifest, in the activity tag, just add
android:alwaysRetainTaskState="true"
Check out following posts:
Android - restore last viewed Activity,
Saving Android Activity state using Save Instance State.
I have a small Android application with a TabScreen as my main screen. I have a small problem where my application currently loses focus on the last Activity the user was on.
This is the scenario:
User launches application
Application shows login screen
User enters login details and goes to tab screen
User leaves application via home key
User presses application icon to return to app and the login screen displays again
I want the application to return to the last known displayed Activity in this case.
What I do at the minute is launch the login screen as the Main/Launcher Actvitiy, then when correct credentials are entered launch the tab screen activity and finish the Login activity.
Is there a launch mode or something I should be using to achieve this?
EDIT: More info
The Tab screen is launched simply like this:
Intent intentTabActivity = new Intent(getApplicationContext(), TabScreenActivity.class);
startActivity(intentTabActivity);
Leaving the application through the home button.
I intend to persist the login state and bypass the login but on smaller applications I have created the application returns to the last displayed activity automatically and does not return to the initial Launcher screen every time and I was wondering why this is not the same behavior in this application.
Also as per my other question HERE the behavior seems to be different for debug and signed releases.
This has always been tested on real devices.
This is the correct behavior. Essentially what happens is as soon as the activity goes in the background it is on the mercy of Android DVM. If DVM feels it needs space it will essentially go ahead and kill your application. So once you try to start the application from the icon it actually restarts it from scratch.
However to solve your problem, you should have a checkbox like "Automatically login" or "Remember password" on the login screen and when the user checks it everytime the app opens it should automatically log you in and take to the next screen. This behavior needs to be implemented by you using some sort of persistent storage.
Might be because you are using your onPause() so that your tabs does some action when the tab is passed.
So eventually when the home key is pressed onPause() will be called which might lead you to this problem. Maybe you will have to check your onPause() for this case.
on home button only onStop is called, are you doing finish of activity on onStop? If not it preserves what was the activity which is top of the stack.