How To Hide Activity If It's Immediately Being Redirected
Solution 1:
just use the same Activity
and then inflate either Fragment
...the result: zero delay.
this can also be done with method .setContentView()
and two XML layouts.
there is no point in showing it, while the user has nothing to do there ...
as a rule of thumb: skip all useless complexity (as others suggested).
Solution 2:
I say use a splash screen. Save the user data in shared preferences and check it in the opening activity. It should be a blank activity with only the shared preferences code and nothing in the xml maybe just a empty layout or space but it should use a style
where the android:windowBackground
is your splash screen logo. Window background is sort of a place holder when an activity is being loaded. This way there is always a splash screen logo with no lag. After making the check direct the user to the login activity or the home activity. Dont forget to finish();
this activity before leaving.
Style:
<stylename="splash"parent="AppTheme.NoActionBar"><itemname="android:windowBackground">@drawable/splash_wallpaper</item></style>
Apply the theme in Manifest:
<activityandroid:name=".activities.SplashActivity"android:theme="@style/splash"><intent-filter><actionandroid:name="android.intent.action.MAIN" /><categoryandroid:name="android.intent.category.LAUNCHER" /></intent-filter></activity>
As the splash_wallpaper
may appear different on different screens use drawable xml which defines its gravity.
splash_wallpaper.xml:
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android"><item><bitmapandroid:gravity="fill"android:src="@drawable/loading"/></item></layer-list>
Solution 3:
I think use share preference to check user login if it login then shared preference value true and after every start check share preference.
Note: open activity should be start activity check user in start activity if false then redirect welcome screen.
ex. it should be help you
https://www.androidhive.info/2012/08/android-session-management-using-shared-preferences/
Post a Comment for "How To Hide Activity If It's Immediately Being Redirected"