Duda Activitys Android

-1

I'm looking for advice because I do not know how I can handle my problem and I would like to know your advice to find out how to deal with it.

I have a Grid view with several buttons, these buttons launch different fragments or activitys, depending on which you press. One of these buttons you press launches a program license confirmation activity (very simple, a couple of edit text and a button)

What I want to do is that before entering this activity I send you a fragment or an activity (what you recommend is better) asking for a password to continue, I have already created my .xml for the password request and I have located where the activity is launched when the button is clicked.

How do you recommend me to do this? How can I do to launch an activity and if the password is confirmed, launch a second activity?

Thank you and greetings.

    
asked by J. Burrueco 12.12.2018 в 11:49
source

1 answer

-1

The status of whether to ask for the password or not (if the last login is still valid) you would save it in SharedPreferences . Here you have to determine what you are going to save to tell you whether or not to ask for the key, it can be from a boolean for a key for only one time, a date and time of expiration, a token, or a combination of these things.

Starting from this, being in SharedPrefrences , it is available for any Activity, and also for any Fragment.

But implementing the control as a Activity separated, a better separation of responsibilities is achieved, given that the control would do the Activity that asks for the key and only if it is verified the correct entry of the same, would call the Activity Real% that you want to execute.

In other words, if the Activity that does the control, does not validate the key, the Activity that you want to protect, does not get to run.

So, in the GridView what you're actually colcoating is the Activity that does the key entry control.

If it is verified that you need to enter the password, show the form. If the key is correctly validated, you update SharedPreferences , and you throw the Activity protected with a Intent .

And if it is not validated, you return to Activity of GridView .

Most likely the Activity that the control throws the Intent to open the Activity protected from onCreate() .

This gives an error if you want to do in the same Thread that is running the onCreate() , that's why it is usually done using a Handler .

final Intent intent = new Intent(this, ActivityParaIniciar.class);
Handler handler = new Handler();
handler.postDelayed(new Runnable(){
            @Override
            public void run() {
                ActivityActual.this.startActivity(intent);
                finish();
            }
}, 100);

ActivityParaInitiate : is the activity protected
ActivityActual : it is the activity that performs the control
Note: It is important to finish () for When you return, do not go back to this activity.

    
answered by 12.12.2018 / 14:04
source