Creating intentions with putExtra

I have been creating Intents for quite some time using putExtra (), and just read in the documentation on Android that I have to prefix "name" with the name of the package. So, instead of 'putExtra ("ButtonText", "Ok") it should be more like putExtra ("com.mycompany.myapplication.ButtonText", "Ok").

Is it really necessary? (it seems without him).

If necessary, what is the advantage?

Also, is the package name caller or caller? If they are callers, then “called activity” must know the name of the caller, which would not be very common.

thank

+5
source share
3 answers

? (, ).

, , .

, , , , . , .

...

A , , , B C. "" A, , "" , -. ...

AppA docs...

To request data processing use:
com.companyA.intent.action.PROCESS_DATA

Pass data with the above intent as an extra named:
<your package name>.SOME_DATA

, AppA , "" , .SOME_DATA, , - . ...

B

Intent i = new Intent(com.companyA.intent.action.PROCESS_DATA);
i.putExtra(com.companyB.SomeApp.SOME_DATA, data);

C

Intent i = new Intent(com.companyA.intent.action.PROCESS_DATA);
i.putExtra(com.companyC.SomeOtherApp.SOME_DATA, data);

, , , , , Android , , .

+7

" ", . , , - , , , , . , , , .

+3

I think this is a BIG idea if you transfer your extended data to a serializable class, say com.mycompany.myapp.MyAppData and sending it as:

intent.putExtra("com.mycompany.myapp.MyAppData",myAppData); //==> out

and get it like:

MyAppData myAppData= (com.mycompany.myapp.MyAppData)intent.getSerializableExtra("com.mycompany.myapp.MyAppData",myAppData; // <== in

Jal

+1
source

All Articles