How to pass Intent Extras?

前端 未结 3 619
不思量自难忘°
不思量自难忘° 2020-12-21 22:23
     public class Menus extends Activity {
//set constants for MediaStore to query, and show videos
private final static Uri MEDIA_EXTERNAL_CONTENT_URI = MediaStore.         


        
相关标签:
3条回答
  • 2020-12-21 23:07

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

    0 讨论(0)
  • 2020-12-21 23:21
    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");
    
    0 讨论(0)
  • 2020-12-21 23:23

    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.

    0 讨论(0)
提交回复
热议问题