0

I have a "Login" xml in layout. And I have another xml is the "List".

In my Application, the user login into the application with e-mail address and password than show their mail list. I did it like that:

        public void onCreate(Bundle savedInstanceState) 
            {
            super.onCreate(savedInstanceState);
            // setContentView(R.layout.main);
            LoginScreen();
            }  

// I am receiving the email and password on the main layout for login page
        public void LoginScreen() 
            {
             setContentView(R.layout.main);  
             EditText emailTxt = (EditText) findViewById(R.id.txtMail);
             EditText passwordTxt = (EditText) findViewById(R.id.txtPassword);
             String email= epostaTxt.getText().toString();
         String password = parolaTxt.getText().toString();
// After receive, call the MailList() for connection and getting the list
             MailList()
            }

// and I use this email and password again into the MailList() for connection with server then receive the mail list

         public void MailList()
            { 
            setContentView(R.layout.list);
            EditText emailTxt = (EditText) findViewById(R.id.txtMail);
            EditText passwordTxt = (EditText)                                                        findViewById(R.id.txtPassword);
            String email= epostaTxt.getText().toString();
        String password = parolaTxt.getText().toString();
            Sending emain and password to the server etc...
            }

This just for now but this code repeat will be continue . I want to get this email and password from Edittxt just one time and use it all the methods. And this code doesn't work also, Maillist doesn't show the list because cannot connect

How can I do that?

halfer
  • 19,824
  • 17
  • 99
  • 186
Merve Gül
  • 1,377
  • 6
  • 23
  • 40
  • (There was a brief answer edited into this question. Answers should go below, not merged into questions please. As I indicate under your post below, you can make a small modification to your update to turn it into the correct answer.) – halfer Nov 27 '18 at 21:55

1 Answers1

0

If I unterstand it well, you simply want to pass data between your Activities, here might be some help : In Android: How do I get variables/data from one screen to another?

EDIT: My new answer, hope it's the good one: Simply create two variables to store the date?

public class LoginScreen extends Activity{

private String email;
private String password;

    public void onCreate(Bundle savedInstanceState) 
        {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.main);
        LoginScreen();
        }  

    // I am receiving the email and password on the main layout for login page
    public void LoginScreen() 
        {
        setContentView(R.layout.main);  
        EditText emailTxt = (EditText) findViewById(R.id.txtMail);
        EditText passwordTxt = (EditText) findViewById(R.id.txtPassword);
        email= emailTxt.getText().toString();
        password = passwordTxt.getText().toString();
        // After receive, call the MailList() for connection and getting the list
        MailList()
        }

    // and I use this email and password again into the MailList() for connection with server then receive the mail list
     public void MailList()
        { 
        setContentView(R.layout.list);

        //Sending emain and password to the server etc...
        //just use the email and password stored above
        yourFunctionToSend(email,password);
        }
}
Community
  • 1
  • 1
XST
  • 178
  • 5
  • Almost correct. These are not my activities actually there is only one Activity class for "main" xml which is the login page. And the "list" xml for Maillist() and it isnt an Activity it is just a xml. I want to pass data between main.xml and list.xml – Merve Gül Mar 31 '12 at 20:36