0

I have an application which needs to run on handheld devices and on tablets/kiosks etc. as far as the design is concern it is easy to maintain but now I have two different logic which needs to different entry points on different device. Following is my requirements.

  1. If it is phone, I want to show login/signup screen then after login/signup it will take to main screen
  2. if it is not phone (I mean if it is tablet/kiosk) it will directly go to main screen.

How can I achieve this? I took some idea from this thread on SO. but it is too old. Is there any reliable advance way to do that what I need.

Please do not mark as copy and do not close it because I am asking for new way to do it. so that the newbies can get it easily on one thread.

A.s.ALI
  • 1,992
  • 3
  • 22
  • 54
  • Isn't [this](https://stackoverflow.com/questions/5832368/tablet-or-phone-android) and [this](https://stackoverflow.com/questions/9279111/determine-if-the-device-is-a-smartphone-or-tablet) your decision? – Евгений Латынин Aug 10 '20 at 05:35
  • I know this can be achieve by that but how to run the activities now ? – A.s.ALI Aug 10 '20 at 05:40
  • 3
    Have the LoginActivity be the launcher activity defined in Manifest. If tablet, don't inflate any layout, just start your MainActivity and call finish on this activity (so it will not be in the back stack). If phone, inflate your layout for LoginActivity and handle your normal operations for logging in. Use the links provided by the other commentor to determine if app is running on a phone or tablet (I haven't tested those links). – kabumere Aug 10 '20 at 05:46
  • that a pretty good idea to start the activity login and directly determining there. – A.s.ALI Aug 10 '20 at 05:47
  • Be sure to design the rest of your application logic correctly. If Tablet/Kiosk users are always unverified (meaning they can never log in), make sure your app always knows the environment it's running in. You don't want to ever be in a situation where the app tries to access user information, yet no user is signed-in, for instance. Can lead to runtime crashes. – kabumere Aug 10 '20 at 05:50

1 Answers1

0

there is no such option for different launchers on different devices, but you can always check what you need in one (and only?) laucher (onCreate method) and start immediately "main" Activity if needed with finishing current "login"

edit:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(checkIfTablet()) { 
        startActivity(new Intent(this, MainActivity.class));
        finish;
        return;
    }
    // rest of code
}
snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • what do you mean? I do not want to show the login screen on tablets but want to show them on the mobile phones. Then How can I run them respectively on those devices? – A.s.ALI Aug 10 '20 at 05:41
  • mark your `LoginActivity` as your launcher and check in `onCreate` `if(tablet) { startActivity(new Intent(this, MainActivity.class)); finish; }. you can add some data do `Intent`s bundle/extra for passing info that `MainActivity` was opened on tablet automatically. and also check out `overridePendingTransition()` method for changing animations for hiding between-activities auto passing – snachmsm Aug 10 '20 at 05:49