S
S
sfilmak2015-05-30 17:10:35
Java
sfilmak, 2015-05-30 17:10:35

How to make a transition to another Activity after entering a password?

Hello!
The question is this. I have two regular Activities. It is necessary to make sure that you can go to the second one only after entering a password (only a password, login, etc. is not required). Searched, but didn't really find anything. Is there a solution? Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rodgenk, 2015-05-30
@Rodgenk

Create 2 activities, in the first we add a text field and a button.
We hang a handler on the button, where we compare the text from the string with the desired one.
If ok, then create an intent and make a transition.
Search keywords: Activity, View (Button, EditText), Intent (Explicit & Implicit), findViewById method.
Good luck!

button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Editable loginEntered = passwordTextField.getText();
                if (!loginEntered.toString().equals("xxx")) {
                    Toast.makeText(getApplicationContext(), "Password not corrected!", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(getApplicationContext(), "Succesful!", Toast.LENGTH_LONG).show();

                    goToTaskListActivity(v);
                }
            }
        });

private void goToTaskListActivity(View v) {
        Intent intent = new Intent(this, TaskListActivity.class);
        startActivity(intent);
    }

R
Renat Iliev, 2015-05-30
@IzeBerg

Welcome to the world of Intent .
After entering the password (pressing the button etc.) put this:

Intent intent = new Intent(this, MyActivity2.class); // MyActivity2 - класс Activity который нужно открыть.
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question