Reputation: 962
HI I am loading a dynamic activity based on if the user is logged in or not. I search through internet and got a solution which asks to create a blank activity, check the condition in oncreate, start new activity based on the condition and finish the blank activity. However, this shows me a blank white screen for 1-2 seconds. How do I avoid it?
(I have deleted the default layout when the blank activity is created.)
Here is my code:
public class BlankActivity extends Activity {
public SharedPreferences mStoredValues;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent loadIntent;
mStoredValues = getSharedPreferences(Constants.STORED_VALUES, 0);
if (mStoredValues.contains(Constants.ACCESS_TOKEN)) {
loadIntent = new Intent(BlankActivity.this, HomeScreen.class);
}
else {
loadIntent = new Intent(BlankActivity.this, Login.class);
}
startActivity(loadIntent);
finish();
}
}
Here are the activity details in Manifest file.
<activity
android:name="com.citrus.citruspay.BlankActivity"
android:launchMode="singleInstance"
android:noHistory="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Upvotes: 0
Views: 1755
Reputation: 546
You should use Fragments to cover this situation. You can choose which fragment you add in your activity dynamically. Try something like this:
public class FirstActivity extends FragmentActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
mStoredValues = getSharedPreferences(Constants.STORED_VALUES, 0);
Fragment fragment;
if (mStoredValues.contains(Constants.ACCESS_TOKEN)) {
fragment = new HomeScreenFragment();
}
else {
fragment = new LoginFragment();
}
getFragmentManager().beginTransaction().add(R.id.container_id,fragment).commit();
}
Upvotes: 1
Reputation: 1189
Add android:theme="@android:style/Theme.Translucent.NoTitleBar"
to your first activity tag in the manifest and see.
<activity android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:name="com.citrus.citruspay.BlankActivity"
android:launchMode="singleInstance"
android:noHistory="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Upvotes: 0