I have an activity (first) that starts a new activity (second). If I returned to my first activity, I want to get some settings I've set at the second activity, without saving in SharedPreferences (just temporary). Is there a way to get public attributes of my second activity? How can I do that on the best way?
            Asked
            
        
        
            Active
            
        
            Viewed 223 times
        
    1 Answers
1
            The best way you can get information returned from the second activity is to invoke it with startActivityForResult.
From Android documentation:
startActivityForResult(intent, CREATE_REQUEST_CODE);
And then, in Activity1 override this:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CREATE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            //ACT
        }
    }
}
Here's a link to referring documentation.
Hope it helps.
 
    
    
        Pablo Santa Cruz
        
- 176,835
- 32
- 241
- 292
- 
                    1described here http://developer.android.com/reference/android/app/Activity.html#StartingActivities – zapl Mar 12 '12 at 19:00
- 
                    I have seen this on one link... resultIntent = new Intent(null); resultIntent.putExtra(PUBLIC_STATIC_STRING_IDENTIFIER, enteredTextValue); setResult(Activity.RESULT_OK, resultIntent); finish(); But I can't call "finish()", I haven't something like a "OK"-Button or "Close". I have a ListView where i can check items and after that I push the back button on my Smartphone. Then i want to add my checked items in a list in my first activity. – Gepro Mar 12 '12 at 19:11
- 
                    Is there any event or Listener to react when I push "back" on my Smartphone ? – Gepro Mar 14 '12 at 08:54
 
    