How to pass Intent Extras?

橙三吉。 提交于 2019-11-29 17:58:53
Intent i = new Intent("com.ave.EDITOR");
i.putExtra("mnt/sdcard-ext", _ID);
startActivity(i);

and in second activity in onCreate method:

String data = getIntent().getStringExtra("mnt/sdcard-ext");

Try this: int data = getIntent().getExtras() .getInt("mnt/sdcard-ext");

You need to call putExtra() on the Intent instance you are passing to startActivity(). In the second activity, you can call getIntent() (a member of Activity) to get the Intent that started the Activity. Do it in onCreate(). Then, it will return you an Intent instance, which you can call get<type>Extra() on depending on what type of extra you packed in there. If your requirements are beyond the basic types supported (things that already implement Parcelable, and the fundamental java types) then you will need to write your own class and implement the Parcelable interface.

See the Intent doc for more info.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!