H
H
Horoko2015-08-10 14:28:46
Java
Horoko, 2015-08-10 14:28:46

How to get null value of Integer class?

I need to pass an Integer type value to another activity, which should be Null by default, but in get ... Extra, there is only getIntExtra which can only get primitive values, without Null. Subject. How do I get my null? If in the default value I should at least insert null.

MainActivity.uris.set(intent.getIntExtra("ids",null), urisis);

on null the studio swears because the method receives primitive type.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Emin, 2015-08-10
@Horoko

Integer is Serializable. Therefore, if you want to transmit in this way, then getIntent().getSerializableExtra()help you. Only on getting, check for null before casting.
But if I were you, I would pass a primitive type, and instead of null, for example, use the default value -1.

X
xdeveloper, 2015-08-11
@xdeveloper

It's a little trickier to use Parcelable.
There is more code to write, but complex objects can be transferred.
public class Ride implements Parcelable { ....}
Intent intent = new Intent(context, ReportActivity.class);
intent.putExtra(Ride.class.getCanonicalName(), ride);
context.startActivity(intent);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question