Home > Software design >  Arrange activities in android studio
Arrange activities in android studio

Time:01-26

I have a splash screen in my project it opens first with intent filter. After that it opens the main activity. But i created new activity that should be opened next to splash screen how to do that?

I have created three activities for example splash screen, main activity, login screen, Splash screen first opens next to that i need to open the login screen next only main activity.

xml code

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:allowBackup="true"
    android:hardwareAccelerated="true"
    android:icon="@mipmap/ic_main"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_main_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.WeatherApp">

    <activity
        android:name=".SplashScreen"
        android:exported="true"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateAlwaysHidden"
        tools:ignore="LockedOrientationActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".LoginActivity"
        android:exported="false"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateAlwaysHidden"
        tools:ignore="LockedOrientationActivity" />
    <activity
        android:name=".HomeActivity"
        android:exported="false"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="stateAlwaysHidden"
        tools:ignore="LockedOrientationActivity" />
</application>

CodePudding user response:

 new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent=new Intent(SplashScreen.this,Login.class);
                finish();
            }
        },4000);

CodePudding user response:

There are few ways to achieve this. This is one of my way.

First, at your AndroidManifest.xml, make sure you make your SplashActivity becomes your launcher. Then, at the onCreate method for your SplashActivity, do some delay, checking some stuff, is this user login or not. Last, go to next activity.

    <activity
        android:name="company.com.ui.SplashActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
  • Related