본문 바로가기
모바일개발(Mobile Dev)/안드로이드개발(Android)

how to deal activity value interaction

by 테크한스 2017. 7. 8.
반응형

If you want to pass data from the preference activity to your main activity use this code:

In your main activity class (launch):

startActivityForResult(new Intent(main.this, preferences.class), 0);

In your preference activity class (set the result):

Intent i;
i.putStringExtra("name", "tom");
setResult(RESULT_OK, i);
finish();

In your main activity class (get the result):

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 0) {
        if (resultCode == RESULT_OK){
            Log.d("test", data.getExtraString("name");
        }
    }
}

You can put as many extras as you want and not only strings but all standard data types.

Intent intent = new Intent(getApplicationContext(), com.jivepia.jiverun.AS_JiveRun_20170702_diary.history.HistoryDetailOfListForWorkout.class);
intent.putExtra("_id", workoutList.get(position)._id);
startActivityForResult(intent,REQUEST_CODE);


반응형