hi all
i have an app with 3 activity. if i launch the app the first time it have to redirect to second activity from first activity. after the first time launch the app it have to go to third activity from first activity. how to do that? please help me. is there way to without using database?
Set a boolean flag in the SharedPreferences. On loading your application you can read that flag.
If it is null: goto Activity 2 and set the flag to true
If it exists: goto Activity 3
Related
I making android app. I have 3 activites:
first(main) activity which is empty and it's like navigation which ask you to add item.
Second activity which is needed for adding item's details and this activity have accept button which leads you to third activity.
Third activity have all data about item and from now on i want my app to make this activity main (default) activity with saving information about it in device memory.
I decided to make it without database because it should be really simple.
Can you help me with making 3rd acitivity main? Maybe there are some tricks.
not clear what you trying to ask. Like if user reached the 3rd activity, in the future if user open the app the app will automatically navigate them to the 3rd activity?
If that's the case, you could save this information in the shared preference, when the app start, the first activity check this value and navigate to the 3rd activity.
Recommend you use a single activity, use fragments for different pages, and use Navigation component to connect them. https://developer.android.com/guide/navigation/navigation-getting-started
I have one Application named Application A, while installing Application A, I want to Open Activity A and While Clicking launcher icon I want to open Activity B. Is this possible? Can anyone help on this?. Thank you.
You can achieve that with SharedPreferences. Use a boolean, at first run you will have to set that boolean to true and it will be saved locally on your phone. Inside your MainActivity or your Application class(if you have one), do a check and start Activity A if boolean is false otherwise start Activity B.
I have an activity to set my preferences the first time that application get opened, but how can I change activity status (move the "MAIN" on another activity)
You cannot move the MAIN Activity to another activity at runtime. It is mandatory to define it while writing Manifest file. If you want to do that as per preferences values then check the preference value everytime and then move to your required activity.
Open SplashScreenActivity--> check preference value here-->If false go to your FirstActivity when app launched newly-->If true go to your AnotherActivity.
Hope you got the concept.
I have two Activities FirstActivity and SecondActivity.
FirstActivity has an intent filter MAIN, LAUNCHER and DEFAULT.
SecondActivity is just a normal activity and no other flags is set in the AndroidManifest.
My application is C2DM enabled and when a notification is received a taskbar Icon is displayed and when clicked it opens SecondActivity.
Arrival of Notifications has two scenarios:
First, My Application is Already Running when notification arrived and second My Application is totally not running.
On the first scenario, everything is fine. A notification is received, i clicked from the notification drop down and my SecondActivity is displayed. When I press back SecondActivity is finished and application goes to the background. When I start my application again from Recent Applications, it displays FirstActivity which is correct since its the MAIN, LAUNCHER and DEFAULT.
On the Second Scenario, A notification is received, I clicked it from the notification drop down and my SecondActivity is displayed. When I press back SecondActivity is finished and application goes to the background. When I start my application again from recent Applications, it displays SecondActivity which is wrong. I am expecting FirstActivity to be displayed because it should be a fresh start.
I tried ForceKilling the application after the second scenario but the result is the same, I needed to restart my phone to be able to start from FirstActivity Again.
Have you guys encountered the same problem? or is it just me? What do you think is wrong with my configuration?
I also tried setting noHistory=false to SecondActivity but still the results are the same.
When you start application from 'Recent Application' shortcut, it will launch the last activity. So you can try to launch the application from the application list, see whether it solves your problem.
It is the correct behavior.. if you start the application through "Recent Application" it will point from the last activity.
Try launching it through normal application list
For your main Activity try to set the lauch mode as "singleInstance" in the AndroidManifest file. for second activity set "Finish On Task launch" to true.
In Second scenario i think activity stack is empty as app is closed . so now you are starting activity2 , means this is the only activity in stack . now desired back behavior can be possible by overriding onbackpress and start activity1 if its second scenario .
you can call your second activity with the flag set no history like this,
intent1.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
This has worked for me several times.
Read from the Android Doc
I have the following application flow in my Android app,
Login->Home->screen1->screen2->screen3->screen4-> logout
In the screen4 I have a log out button, which allows the user to logout from the application and re-login. When I re-login to the app, the previous data is still shown. Is there a way to start the application fresh when the user logs out from the app?
NOTE: all the above activities launch mode set to "single task",
See if that helps - http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TOP
(This and other flags)
You could set a static flag when the user clicks logout and in each activity check that flag in onResume() and if it's set call finish(). That's kind of hacky though.
Well I dont know it its that what you want but can finishing activity before starting another and storing login in Application Context can help?
Configure this for your activity in AndroidManifest.xml. The attribute is android:clearTaskOnLaunch.