1

I wanna start a new activity and sent a parametter to her. And according to what has been sent activity will behave in a way or another. (Sorry my bad english) The options depends of a button. If "option1" or "option2" is pressed, the SettingsActivity will come the same, except in a little details, so I have send a parameter to separate the two ways inside "SettingsActivity".

I have the next:

option1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), SettingsActivity.class);
                startActivityForResult(myIntent, 0);
            }

        });
option2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                Intent myIntent = new Intent(view.getContext(), SettingsActivity.class);
                startActivityForResult(myIntent, 0);
            }

        });
Genaut
  • 1,810
  • 2
  • 29
  • 60

2 Answers2

1

To call a new activity you can do this thing by the following code. where a intent can call a newactivity. here xyz is the current activity and xyz1 class is the target activity.

 Intent i = new Intent(xyz.this, zyz1.class);
 i.putExtra("post", 2);
 startActivity(i);
coading fever
  • 221
  • 2
  • 10
0

Use the .putExtra("Name", name); and in the settingsActivity use this: getIntent().getExtras().getString("Name");

.putExtra("Name", name); - The "Name" is kind of like a temporary id, and the second value is your string.

To get it using the getIntent().getExtras().getString("Name");, use something like

String name = getIntent().getExtras().getString("Name"); in the SettingsActivty