将HashMap从一个活动传递到另一个活动,android
我正在编写一个android应用程序来显示附近的位置。然后我将其存储在如下的hashmap列表中将HashMap从一个活动传递到另一个活动,android,android,Android,我正在编写一个android应用程序来显示附近的位置。然后我将其存储在如下的hashmap列表中 List<HashMap<String, String>> places = null; 在下一个活动中,我这样做了: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout
List<HashMap<String, String>> places = null;
在下一个活动中,我这样做了:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_airports);
Bundle extras = getIntent().getExtras();
String[] places=extras.getStringArray(Intent.EXTRA_TEXT);
但是putExtra方法不接受List
使用putExtra(String,Serializable)
在Intent中传递它,并使用getSerializableExtra(String)
方法检索它
另外,请使用ArrayList
而不是List
使用intent.putExtra(字符串,可序列化)-请参阅。
i、 e
在接收活动中使用
HashMap<String, String> places = (HashMap<String, String>) intent.getSerializableExtra("placesHashMap");
hashMapplaces=(HashMap)intent.getSerializableExtra(“placesHashMap”);
什么是
当前类的可序列化截图
1。将意图从上下文类传递到新类
Bundle b=getIntent.getExtra();
if(b!=null)
{
yourhasmaplist=b.getSerializableExtra("key");
}
您是对的,putExtra方法不接受列表。。。那么问题是什么呢?@Scott问题是:有没有办法通过“名单”
HashMap<String, String> places = (HashMap<String, String>) intent.getSerializableExtra("placesHashMap");
HashMap<String, String> hashMap= adapter.getItem(position);
Intent intent = new Intent(OneActivity.this, SecondActivity.class);
intent.putExtra("key", value);
startActivity(intent);
Bundle b=getIntent.getExtra();
if(b!=null)
{
yourhasmaplist=b.getSerializableExtra("key");
}