cancel(getIntent().getExtras().getInt(“notificationID”)); what is the return...?
cancel(getIntent().getExtras().getInt(“notificationID”));
why we use of dot operator in between these methods? as cancel(int) method takes only one integer parameter.it has 3 me开发者_运维知识库thods as parametr.....what exactly the code will do..?
This is a short way to write:
Intent intent = getIntent();
Bundle bundle = intent.getExtras(); // or getIntent().getExtras();
int i = bundle.getInt(“notificationID”); // or getIntent().getExtras().getInt(“notificationID”);
cancel(i); // or cancel(getIntent().getExtras().getInt(“notificationID”));
What you do is to invoke methods on the return value of each method.
You should try going through the concepts of object oriented programming first.
To answer your question, getIntent()
returns an object of type intent. We call the getExtras()
on the Intent object which returns an object of type Bundle. Then we call getInt()
on the Bundle object to finally get the int we want to pass to the cancel()
method.
The statement is equivalent to :
Intent i = getIntent();
Bundle b = i.getExtras();
int id = b.getInt("notificationID");
cancel(id);
If we don't need any of the intermediate objects, we can write the whole thing in a single line.
Hope that helps.
cancel(getIntent().getExtras().getInt(“notificationID”));
.. even here cancel is getting only 1 arguement... because.. getIntent()= returns an intent
intent.getExtras = returns the values it stores
if extras has some object then .getInt(“notificationID”) = returns an Int value
.. So finally only thing remaining is integer...
精彩评论