0

I'm creating an app that has different dashboards for users and me. how can I change the launcher activity when users log in and when I log in??

This is the part of the code where I need to switch launcher activity

 if (email.matches("myEmail@gmail.com")) {
      startActivity(new Intent(LoginActivity.this,AdminDashboardActivity.class));
      finish();
} else {
     startActivity(new Intent(LoginActivity.this,DashboardActivity.class));
     finish();
 }
Shibl
  • 87
  • 9
  • If even you or anyone login in your app that means you already launched your app using the launcher activity. I think your usecase is something else. – Dinkar Kumar May 01 '21 at 08:57
  • currently, my launcher activity is the user's dashboard when I log in with my details it's ok and it's going to admin dashboard activity. but when I close the app and relaunch it.it's showing users dashboard, even if I am logged in before i closed the app – Shibl May 01 '21 at 09:15
  • 1
    I think you might be interested in [this](https://stackoverflow.com/questions/52895188/how-to-redirect-multiple-types-of-users-to-their-respective-activities). – Alex Mamo May 02 '21 at 08:10

2 Answers2

0

I got the solution

I used handler to delay intent and startActivity, which helped me to change the activity as I needed

Shibl
  • 87
  • 9
-1

You can check it from a splash screen activity.

Inside the splash screen activity you can do something like this:

if (email.equals(myEmail)) do something
else do something
GSepetadelis
  • 272
  • 9
  • 24
  • If you are checking anything in splash means splash is your launcher activity always and you are not changing launcher activity on any condition – Dinkar Kumar May 01 '21 at 08:58
  • 1
    This is the only way to navigate each user to a different screen I think. There is not officially way to change the launcher activity – GSepetadelis May 01 '21 at 09:01
  • Yes, but that means there is no answer to this question, kind of not possible by design. – Dinkar Kumar May 01 '21 at 09:06
  • 1
    @dinkar_kumar exactly, for now I think this is not possible, but if I find something witch can help you I will make a new answer to your question :-), have a nice day – GSepetadelis May 01 '21 at 09:18
  • 1
    Also if you want you can check this similar post: https://stackoverflow.com/questions/29517277/how-can-i-configure-launcher-activity-programmatically-in-android/29517389 – GSepetadelis May 01 '21 at 09:27