Make it appear as if only one activity has launched when implementing a EULA

205 Views Asked by At

I'm trying to implement a one time EULA and password creation screen in my app.

I strife to do this as clean and seamless as possible. My current implmentation involves a SharedPreference that needs to be set, when it's not, it should display the EULA and password creation screen.

/**
 * 
 * @param context
 * @return
 */
public static boolean isFirstLaunch(Context context) {
    SharedPreferences reader = context.getSharedPreferences(
            PREFERENCES, Context.MODE_PRIVATE);
    String apiKey = reader.getString(APIKEY, "");

    return apiKey == "";
}

The API key is set when the user completes accepting the EULA and has created a password. However I see the previous activity still being launched/animated. So I have been trying remove the animation on the first activity, but no luck as of yet.

In the activity:

@Override
protected void onCreate(Bundle arg0) {
    super.onCreate(arg0);

    if (InitialLoading.isFirstLaunch(this)) {
        Intent intent = new Intent(this, EndUserAgreementActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        startActivity(intent);
        //getWindow().setWindowAnimations(0);
        overridePendingTransition(0,0);
        finish();

        return;
    }

    if (InitialLoading.isPasswordLoginEnabled(this)) {



    }

    Intent intent = new Intent(this, OverviewActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_HISTORY|Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NO_ANIMATION);
    startActivity(intent);
    finish();
}

Do you guys know how I can make it look as if only one activity has been launched in all scenario's:

  • (DO NOT DISPLAY)lauched activity -> EULA -> Password Creation -> launched/other activity
  • (DO NOT DISPLAY)lauched activity -> Authentication screen -> launched/other activity
  • lauched activity

I currently still see a flicker of the previous activity when I try to launch the EULA. I have checked Whatsapp and that app does show a flicker when launching the non-EULA activity, so I wonder if this is possible.

I already have a settings screen that disables the password screen that would launch if the authentication option remains enabled, so no worries there.

Anyway, thanks for the help.

1

There are 1 best solutions below

1
On BEST ANSWER

What you may have a look at is the concept of Fragments. The idea is to split the UI of your activity into reusable Fragments that can be interchanged at runtime.

So in your onCreate method, you can check whether a EULA screen is needed and then inflate the corresponding EULA Fragment, or in the other case display the password ui Fragment. This should reduce the flickering by avoiding to start a new activity in favour of reusing the active one.