0

我正在尝试将带有整数值的包从片段活动页面传递到新的活动页面。但是整数似乎没有被传递,因此它的值始终为 0。是什么导致了这个问题?我错过了什么吗?

这是片段活动:

public class TravelogueSEOPageFragment extends SherlockFragment {

    //method here that creates the bundle to be passed on to the new activity
    public void Map(View v){
        Intent offlineMapView = new Intent(v.getContext(), TOfflineMapView.class);
        Bundle b = new Bundle();
        b.putInt("id", travelogueID);
        offlineMapView.putExtras(b);
        startActivity(offlineMapView);
    }
}

这是新的 Activity 类:

public class TOfflineMapView extends Activity{

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle b = getIntent().getExtras();
        int tID = b.getInt("id");

        ...//remove unnecessary codes
    }
}

所以我的 tID 永远为 0。这是错误的做法吗?

4

0 回答 0