开发者

How can I pass a value from a new Activity to an old Activity?

开发者 https://www.devze.com 2023-01-13 00:21 出处:网络
I am using two Activities, Old Activity and New Activity. I want to pass a value from New Activity to Old Activi开发者_运维技巧ty. How can I accomplish this?an example::

I am using two Activities, Old Activity and New Activity. I want to pass a value from New Activity to Old Activi开发者_运维技巧ty. How can I accomplish this?


an example::

            Bundle bundle = new Bundle();
            bundle.putInt("newPicPosition", position);              
            Intent intent = new Intent(NewActivity.this, OldActivity.class);
            intent.putExtras(bundle);
            setResult(Activity.RESULT_OK, intent);
            finish();

use setResult()

public final void setResult (int resultCode, Intent data) Since: API Level 1 Call this to set the result that your activity will return to its caller.

Parameters::

resultCode The result code to propagate back to the originating activity, often RESULT_CANCELED or RESULT_OK
data The data to propagate back to the originating activity.

0

精彩评论

暂无评论...
验证码 换一张
取 消