Using putExtra to pass values to intent service

前端 未结 2 1241
猫巷女王i
猫巷女王i 2020-12-29 06:45

within my main activity I have the following code:

EditText usernameText;
EditText passwordText;
public void sendLogin (View loginview){
    Intent i = new I         


        
2条回答
  •  臣服心动
    2020-12-29 06:59

    1. For sending usernameText and passwordText to NetworkService do this....

    Intent i = new Intent(Your_Class_Name.this, NetworkService.class);
       i.putExtra("username", usernameText.getText().toString());
       i.putExtra("password", passwordText.getText().toString());
       startService(i);
    

    2. To receive the data in NetworkService do this....

    Intent intent = getIntent();
       String userName = intent.getExtras().getString("username");
       String password = intent.getExtras().getString("password");
    

提交回复
热议问题