創(chuàng)建ViewPerson活動(dòng)的意圖并傳遞PersonId(例如,用于數(shù)據(jù)庫(kù)查找)。
Intent i = new Intent(getBaseContext(), ViewPerson.class); i.putExtra("PersonID", personID);startActivity(i);
然后,在ViewPerson活動(dòng)中,您可以獲得額外的數(shù)據(jù)包,確保它不是NULL(如果有時(shí)不傳遞數(shù)據(jù)的話),然后獲取數(shù)據(jù)。
Bundle extras = getIntent().getExtras();if(extras !=null){
personID = extras.getString("PersonID");}
現(xiàn)在,如果需要在兩個(gè)活動(dòng)之間共享數(shù)據(jù),也可以使用GlobalSingleton。
public class YourApplication extends Application {
public SomeDataClass data = new SomeDataClass();}
然后在任何活動(dòng)中調(diào)用它:
YourApplication appState = ((YourApplication)this.getApplication());appState.data.CallSomeFunctionHere();
// Do whatever you need to with data here. Could be setter/getter or some other type of logic