简体   繁体   中英

How to send data from one activity to another by using getIntent() instead of usinf new Intent();

usually we send data from one activity to another by using:-

Intent i=new Intent("<action name>");
i.putExtras("name",data);
startActivity(i);

My question is can we send data from one activity to another by using:-

Intent i=this.getIntent();
i.putExtras("name",data);
setResult(Activity.RESULT_OK,i);
finish();

If yes please explain the concept. Also,these two classes are in the different projects in Eclipse.My another question is, is it possible to send data through intent to another activity situated in another project??

So you're starting from Activity A and going to Activity B using startActivityForResult()

Now we're in Activity B and want to go back to Activity A:

Intent i = new Intent();
if(getIntent().getExtras() != null) i.putExtras(getIntent().getExtras()); 
setResult(Activity.RESULT_OK, i);
finish();

Doing something like that will allow you to pass back the extras from the calling Intent (if they exist), which would then be reachable from Activity A's onActivityResult() method.

Yes. You can do so, when you call another intent for a result. ie startActivityForResult(Intent,Request_Code);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM