mertaydin
mertaydin

Reputation: 2244

How to control Bundle null or not?

i have 3 Activity in my application and i'm reaching a activity either with a bundle and without bundle and i'm trying to check the bundle null or not. If it's null, open activity, if it's not null write the value to edittext.

here is my code.

Bundle veriAl = getIntent().getExtras();

EditText who_detail = (EditText)findViewById(R.id.who_detail);
String gelen_deger = veriAl.getString("reply_user").toString();

if(gelen_deger.equals(""))
{
   who_detail.setText(veriAl.getString("reply_user"));
}

Upvotes: 0

Views: 552

Answers (2)

Mohamed_AbdAllah
Mohamed_AbdAllah

Reputation: 5322

Use:

String gelen_deger="";
if(veriAl != null && veriAl.containsKey("reply_user")) gelen_deger = veriAl.getString("reply_user").toString();

Upvotes: 1

Shruti
Shruti

Reputation: 5591

try this :

if(veriAl != null){
String gelen_deger = veriAl.getString("reply_user").toString();
}else{
//you got null from bundle
//open other activity here 
}

Upvotes: 3

Related Questions