My requirement is to decide which activity should be launched bt at runtime. For example, if user is logged in then Activity A should be launched else Activity B should be launched. I have also tried using the logic that is saving the data in preference and then checking whether the user is present or not and den making an intent launch accordingly. But this approach gives a slight lag at the start while checking the user is present or not in the preference. Can activity-alias can help in this scenario?
Asked
Active
Viewed 193 times
0
-
This might be inspiring! https://stackoverflow.com/questions/34829931/start-with-different-activity-on-first-launch-of-android-app – stkent Apr 20 '18 at 13:38
2 Answers
1
In most of the application developers use a splash screen to perform certain tasks. In your case, you can add a splash screen for a few seconds(2 or 3 sec) in which you can check the login status of the user, from shared preference, which will decide which activity needs to be launched next.

Kinjal Rathod
- 499
- 4
- 12
-
I got your point, but what if the screen to be decided is between splash and some other activity? – fi - Anand Dubey Apr 21 '18 at 17:21
-
I don't think you can change the laucher activity at runtime, I have found this answer check if its helpful.https://stackoverflow.com/a/2776180/8663757 – Kinjal Rathod Apr 22 '18 at 08:40
0
The normal solution for this is to check if the user is logged in at the top of onCreate of the login activity, and if so immediately start activity B, finish itself, then return.

Gabe Sechan
- 90,003
- 9
- 87
- 127
-
Actually this approach is giving me a slight launch delay. This is the reason for not adapting this solution. – fi - Anand Dubey Apr 20 '18 at 14:05