Its very simple.
I think you remember this code.
Button btn.(Button)findViewById(R.id.btnStart);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(SolutionDudeActivity.this,Login.class);
startActivity(intent);
});
When I press the START button in my main page, I can move to the Login screen.
Now think, I want to display my name in welcome screen when I logged in to the application. I'm using putExtra and getExtra methods. All I want to do is modify the code like below.
Intent intent = new Intent(Login.this,Welcome.class);
intent.putExtra("user", name.getText().toString());
startActivity(intent);
You can use "putExtra" method to pass values. First parameter is to identify what you are passing. In here I'm getting the string value of EditTextBox and pass it to welcome screen. I have to do one thing. That is change the code of Welcome.java to catch the passed value.
package com.solution.dude;
import android.app.Activity;
public class Welcome extends Activity {
@Override
protected void
onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.weLcome);
TextView tv.(TextView)findViewById(R.id.user);
tv.setText("Hello " + getIntent().getExtras().getString("user") + ",");
And the output will be appeared like this.
And that's it.
Next chapter we'll look at how to create a simple loading screen..
See you in the next chapter.
Thanks for this post its really interesting i bookmark your blog for future stuff like this..
ReplyDelete2004 Mini Cooper AC Compressor
Thank You very much for your feedback sheena !
Delete