-1

So, i know there's lot of examples with Viewtext and EditText, but i'm struggle with if-else, i have Activity A :

button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View arg0) {

        if(Long.parseLong(IMEI) == IMEI2){
            IMEI .equals(IMEI2);
            textView.setText("IMEI NUMBER : " + IMEI);
            Intent intent = new Intent(imei.this, menu_utama.class);
        }else{
            AlertDialog.Builder builder = new AlertDialog.Builder(imei.this);
            builder.setMessage("Data IMEI and IMEI2 did not match")
                .setNegativeButton("Retry", null)
                .create()
                .show();
        }

    }
});

now i want to use : if(Long.parseLong(IMEI) == IMEI2) = success i want to use it in Activity B in an if(that condition in Activity A success){do something}else{} condition too. How i do this ?

Ram Koti
  • 2,203
  • 7
  • 26
  • 36
borneo
  • 97
  • 9

2 Answers2

0

Based on your question and your code, my answer is,

Intent intent = new Intent(imei.this, menu_utama.class);
startActivity(intent);     //  Place this line to move Activity B

If you know already this line, Use Bundle. Bundle can use your previous activity data to another activity.

Siva7170
  • 3
  • 3
  • i'm trying to put `Intent intent = getIntent();` inside `@Override public void onCreate() { super.onCreate(); Intent intent = getIntent(); Bundle bundle = intent.getExtras(); final boolean success = bundle.getBoolean("key");` it turn red – borneo Feb 22 '18 at 07:10
0

You can ,using lots of ways: like

Activity A:

//when your condition has been meet

Intent intent=new Intent(context,ActivityB.class);
intent.putExtra(key,true)  // set true boolean here
startActivity(intent)

Activity B:

if(getIntent().getExtra().getBoolean(key)){
    // handle your event here
} else{

}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
chari sharma
  • 462
  • 2
  • 16
  • i did in Activity A, but in my Activity B my getIntent() and key is red if(getIntent().getExtra().getBoolean(key)){} – borneo Feb 22 '18 at 05:49
  • turns out my problem has something to do with `public class MyApplication extends Application {}` but if i try with `extends AppCompatActivity{}` my `getIntent();` correct, what should i do with the rest with my app that has something to do with `extends Application` – borneo Feb 22 '18 at 07:16