0

I put in my activities 2 button it's yes and no

When click Yes, I wanna send %5 text to next activity. If no I don't wanna send nothing. My activity;

public class Soru1 extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_soru1);
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    Typeface tf = Typeface.createFromAsset(getAssets(),
            "fonts/Quicksand-Medium.ttf");
    TextView tv = (TextView) findViewById(R.id.ques_text);
    tv.setTypeface(tf);

    Typeface te = Typeface.createFromAsset(getAssets(),
            "fonts/Quicksand-Bold.ttf");
    TextView ts = (TextView) findViewById(R.id.numbers);
    ts.setTypeface(te);

    Typeface tt = Typeface.createFromAsset(getAssets(),
            "fonts/Quicksand-Bold.ttf");
    TextView sl = (TextView) findViewById(R.id.progress_number);
    sl.setTypeface(tt);

    ImageButton btn = (ImageButton)findViewById(R.id.yes_button);
    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            ImageButton btn = (ImageButton)v;
            btn.setImageResource(R.drawable.yes_button_pressed);
            Intent inf=new Intent(Soru1.this,NextActivity.class);
            startActivity(inf);

        }
    });

    ImageButton btno = (ImageButton)findViewById(R.id.no_button);
    btno.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            ImageButton btn = (ImageButton)v;
            btn.setImageResource(R.drawable.no_button_pressed);
            Intent inf=new Intent(Soru1.this,NextActivity.class);
            startActivity(inf);
        }
    });
}

}

And I'll take this %5 and I'll use to all next activities. For example: Activity 1 - Yes: %5 Activity 1 - No: %0

If clicked yes

Activity 2 - Yes: %10 Activity 2 - No: &5

and more next more next more next.

How I can do that? on my activity? Thanks a lot.

Onur YIlmaz
  • 51
  • 2
  • 9

1 Answers1

1

With Bundles!

To give the values

Intent intent = new Intent(getApplicationContext(),SecondActivity.class);
intent.putExtra("myKey",AnyValue);  
startActivity(intent);

To get the values in your new intent

Bundle extras = intent.getExtras(); 
String tmp = extras.getString("myKey");

Read more about this here.

Archimedes
  • 231
  • 1
  • 2
  • 13