2012-09-06 65 views
0
Activity_A: 

{ 
    //calling Activity B where i find the user current location lat and lng 
    Intent intent = new Intent(Activity_A.this, Activity_B.class); 
    startActivity(intent); 
} 

Activity_B 
{ 
    //after getting user lat and lng, use them in Activity_C to show the initial marker position 
    Intent intent = new Intent(Activity_B.this, Activity_C.class); 
    startActivity(intent); 
    //i don't this Activity_B to show up on back press in Activity_C hence finish(), anyways this Activity_B has no layout 
    finish(); 
} 

Activity_C: 

{ 
    //Show a map with marker at position using lat, lng values from Activity_B, allow user to drag the marker and get the new lat, lng. and then finish this Activity to go to Activity_A 
    finish(); 
} 

我想這Activity_C發回新的緯度,經度,以ACtivity_A值沒有任何共享偏好或全局變量,我的意思是通過使用startActivityForResultonACtivityResult在這種情況下如何從活動中獲取數據?

回答

1

使用setResult和內部活動A進去OnActivityResult的所有數據。但是從A開始活動到B,您需要使用startActivityForResult和結果代碼。否則,您可以使用broadcast receivers,這些活動獨立於您可以在任何活動課程中發送和接收的所有活動。

0
You can try chaining the activities like this:: 


Activity_A: 

{ 
    //calling Activity B where i find the user current location lat and lng 
    Intent intent = new Intent(Activity_A.this, Activity_B.class); 
*****startActivityForResult****** 

    startActivity(intent); 
} 

Activity_B 
{ 
    //after getting user lat and lng, use them in Activity_C to show the initial marker position 
    Intent intent = new Intent(Activity_B.this, Activity_C.class); 
    startActivity(intent); 
    //i don't this Activity_B to show up on back press in Activity_C hence finish(), anyways this Activity_B has no layout 
*****startActivityForResult****** 
    finish(); 
} 

Activity_C: 

{ 
    //Show a map with marker at position using lat, lng values from Activity_B, allow user to drag the marker and get the new lat, lng. and then finish this Activity to go to Activity_A 
    finish(); 
}