I'm trying to make an Android app that has a Onboarding Screen that should teach the user how to use the app. I want to show this screen only the first time the app is opened. My Main Activity have a Navigation Drawer with fragments(recyclerview) and this screen should be shown as launcher once the Onboarding screen was already seen or isn't the first time that the app is opened.
So, the question is: what activity I should select as Launcher in the manifest?
P.S.:Sorry about my bad english in advance.
There are different approaches to do that. You can create an Activity without layout and name it DispatcherActivity. Make this activity as launcher activity.
You can then use SharedPreferences to determine if this first launch or subsequent launch (store a boolean isFirstLaunch, set it to true as soon as OnboardingScreen is launched) in onCreate of this activity. If its first launch, then start the OnboardingActivity else start your MainActivity.
Related
I have two activities in my Android project:
LoginActivity
DashboardActivity
When user starts the app, auto sign-in tasks are done on LoginActivity (takes few seconds, fullscreen spinner is shown), then DashboardActivity is launched. On the DashboardActivity we are again loading some blocking data (again, fullscreen spinner).
I would like to use single fullscreen loading screen for this, that will be shown as soon as LoginActivity start loading data and end when DashboardActivity stops loading data.
Current status is, that I have duplicated fragment that is used in both Activities. This of course causes the spinner to change (blink/slide animation) when you change activities.
I was thining about having third activity that will get launched as an overlay until both activities finish their work, but I am not sure if that is possible.
Sir,
The last opened activity will be saved and when opening the app, the last opened activity will be opened. But app reopen every time then see splash screen then go last open activity, Please help me for it..
Please send this code
That's simple. When the activity is closed, in the activity class, override the onStop() method and save the activity name in the SharedPreferences. Then in the main activity, get the SharedPreferences variable and open the activity using an intent. Hope this helps. For more info, ping using a comment. I'll share the working code.
I am working on a tracking application that use another third party application such as google map.
Lets assume my application has 4 activities ( act1, act2 , act3 and act4 ).
on act3 activity i am calling google map application to calculate the distance and view the routing. But once i clicked on the back button of the tablet, or go back to the home page and clicked on the launched icon, the act1 is displaying instead of act3.
However, my application is still running on background.
So my question here how can i make the application is opened the last activity which is act3 in our example, when the back button is pressed or when the launched icon is clicked.
Thanks,
Store the name of the running activity into shared preferences in the onPause of every activity (if you're exiting by pressing home button) or in onBackPressed (if exiting an activity by pressing back button).
Then create a launcher activity which reads the shared preferences and launches the specific activity.
Lastly remove the launcher activity from the activity stack so that the app doesn't go back to it on pressing back button.
I'm writing an Android app that connects to a computer and acts as a mouse. I want the screen to remain awake only while the app is being used. I know I can use getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
to keep the screen on during an activity, but is there a way to keep the screen on for all activities or would I have to use that line of code in every onCreate method for each activity?
You would have to use that line within each activity.
Or you could use Fragments and set it once in the only activity and it will be applied to each fragment from then on.
I have an app that circles around the main activity (a main menu). In each other app there is an option menu item that directs to this activity.
At first, I always started a new main activity when this item was selected. Using the intent bundle, I did tell the main activity that some initializations I do on a fresh start were not necessary.
However, I didn't quite like the overall behavior. I stumbled upon android:launchMode="SingleTask" and this seemed to help: now I don't recreate my main menu activity all the time; also, if I press the "back" button I come back straight to the home screen. This feels quite nicely like a proper "main" menu.
My problem now is this: if I run another activity of my app, press home button and then reopen my app (e.g. using "last apps"), then I don't go back to the last activity, but to the main one. The other activity is destroyed.
Any ideas how I can implement the behavior of SingleTask without only being able to return to one activity?
If your other activities are declared normally with activity defaults in Android, then going back to your app should take you to the same activity where you left off (using the hardware home button)
However remember that the Android system kills applications when it requires system resources. So your app may have been killed when you went to the other application. Then when you get back to your app, the default launcher activity will be restarted, which is your Menu activity.
To get back to the main activity from any activity, do this:
public static void goHome(Context context) {
final Intent intent = new Intent(context, HomeActivity.class); //give name of your main activity class here
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
That will clear the activity stack and get you back to your main activity. As you declared singleTop, it will bring the existing main activity to the foreground. The flag Intent.FLAG_ACTIVITY_CLEAR_TOP will remove all activities in the stack on top of the main activity. (I am assuming you are within the same application).
Now, all your other activities only need to include a button whose click listener invokes the method goHome();
From your main activity, if you press the hardware back button, it should exit your app.
Why not call finish() on the activities that were created by the main activity? This way you return to the main activity, without creating a new one...
I think you should save the state of you activity before starting another activity, and then resume your activity whenever you come back on last activity.
see Activity Life cycle from Android
http://developer.android.com/guide/topics/fundamentals/activities.html