Start Splash Screen after initial App intro launch - java

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.

Related

Using splash screen as a loader

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.

Activity starts but I need to minimize to see it

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.

Dialog Fragment Not Displaying on Launch

So I have some application, on startup it launches a splash screen activity and checks to see if a user account has been linked to the app. If one has the app launches the main activity and bypasses the splash silently. If there is no user account it pulls down a database in a AsyncTask and asks the user to Login/Create an Account.
On first startup the app syncs with a server and pulls down a database. I'm trying to get a DialogFragment with an indeterminate progress bar to display as this database is pulled down. Right now the DialogFragment is created in the onPreExecute() of the AsyncTask, the AsyncTask is executed in the Activity's onStart() method the problem I'm having is that the dialog is not being drawn to the screen.
I have debug logging that shows that the dialog's onCreate() is executing and the sync is successful. The dialog is shown/dismissed in onPreExecute() and onPostExecute() respectively both of which execute on the UI thread. I realize that if the database download is fast this won't display very long but I'm not seeing even a brief flash of the dialog in the emulator.
Could this be a 'problem' with the emulator where all the dialog's frames are being skipped or am I not creating the dialog at a point where it would actually be drawn to the screen.
From your description I see 2 possible reasons:
1. Maybe you doesn't show right the DialogFragment, see example.
2. The AsyncTask is launched in a different thread (Not on UIThread), so if you need to access the UIThread (from the AsuncTask), try to override onProgressUpdate see tutorial.
Hope it was helpfull.

Start Activity on background

I have an app that responds to Internet message by creating a new Activity and user has 20 seconds to respond.
The problem is when the app is running on background.
I can show a notification, but when the user returns to the App the new Activity isn't started.
Is there any way to start an Activity even when the App isn't on foreground (without the activity getting focus) or any easy workaround where the activity would start right after returning to the app? (which would be worse solution, cause I would have to rework the sync timer :))
Thanks
Take a look at the Activity life cycle
Here you have the onResume() method you can override and do something before the Activity itself is shown. From there you could do some kind of check that you are returning from a notification or a check on that the user has to answer something now and launch a new Activity from the onResume() method.

Android - Show last viewed Activity When press (Home Button-->App Shortcut)

I came to do the eternal question, which so far have not found a solution, I searched on the internet the same problem but found a final solution to this problem.
when I have 2 activities open and I pull the 'Home Button' and then press the shortcut for my application, it shows me again the first activity (the launcher activity), and then to return to the activity that was displayed, I have to press the back button.
what is the solution to this problem?
I want to press the shortcut of my application (after having left my application by pressing the Home Button) show me the last activity was displayed, instead it shows me the first activity (activity launcher).
Thanks in advance.
That is the expected behavior. The launcher will launch the Activity with the filter android.intent.action.MAIN.
There are ways to work around it, though. A very simple one is to have a boolean flag mRunning that you will set to true upon launch. If true, then on the onStart() method you start an intent to launch your second Activity; if false, then go on with setContentView().
If you have several activities to go back to, then a feasible approach is to save the current activity in SharedPreferences and launch it the same way.
Alternatively, your main Activity may be just an entry Activity whose only job is to start the last Activity used.
EDIT: I found this duplicate question: How to make an android app return to the last open activity when relaunched? that has a much better ansewr than mine.
Your application is still running in the background when you press the home button. finish() the activity when you press the Home button if you want to go back.
Depending on whether or not your main activity is ever launched by another activity, or only the application icon, you can use a much simpler solution. If your main activity is only launched by the application icon, you can use isTaskRoot() to check if your main activity is being launched as a fresh start to the application, or if the user is returning and the main activity is being laid on top of other activities that you wish to display instead.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (! isTaskRoot()) {
finish();
} else {
...
}
}
You can use startActivityForResult replace for startActivity when you want to open another Activity.

Categories

Resources