android– 如何传递Intent Extras?

android– 如何传递Intent Extras?,第1张

概述publicclassMenusextendsActivity{//setconstantsforMediaStoretoquery,andshowvideosprivatefinalstaticUriMEDIA_EXTERNAL_CONTENT_URI=MediaStore.Video.Media.EXTERNAL_CONTENT_URI;privatefinalstaticString_ID=MediaStore.Video.Media

     public class Menus extends Activity {//set constants for MediaStore to query, and show vIDeosprivate final static Uri MEDIA_EXTERNAL_CONTENT_URI = MediaStore.VIDeo.Media.EXTERNAL_CONTENT_URI;private final static String _ID = MediaStore.VIDeo.Media._ID;private final static String MEDIA_DATA = MediaStore.VIDeo.Media.DATA;//flag for which one is used for images selectionprivate GrIDVIEw _gallery; private Cursor _cursor;private int _columnIndex;private int[] _vIDeosID;private Uri _contentUri;protected Context _context;/** Called when the activity is first created. */@OverrIDepublic voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.main);    _context = getApplicationContext();    _gallery = (GrIDVIEw) findVIEwByID(R.ID.vIDeoGrdVw);    //set default as external/sdcard uri    _contentUri = MEDIA_EXTERNAL_CONTENT_URI;    //initialize the vIDeos uri     //showToast(_contentUri.getPath());    initVIDeosID();    //set gallery adapter    setgalleryAdapter();}private voID setgalleryAdapter() {    _gallery.setAdapter(new VIDeogalleryAdapter(_context));    _gallery.setonItemClickListener(_itemClicklis);}private AdapterVIEw.OnItemClickListener _itemClicklis = new OnItemClickListener() {    public voID onItemClick(AdapterVIEw<?> parent, VIEw v, int position, long ID)     {        // Now we want to actually get the data location of the file        String [] proj={MEDIA_DATA};        // We request our cursor again        _cursor = managedquery(_contentUri,                proj, // Which columns to return                null,       // WHERE clause; which rows to return (all rows)                null,       // WHERE clause selection arguments (none)                null); // Order-by clause (ascending by name)        // We want to get the column index for the data uri        int count = _cursor.getCount();        //        _cursor.movetoFirst();        //        _columnIndex = _cursor.getColumnIndex(MEDIA_DATA);        // Lets move to the selected item in the cursor        _cursor.movetoposition(position);        Intent i = new Intent();        i.putExtra("mnt/sdcard-ext", _ID);        startActivity("com.ave.EDITOR");    }};

以上是我的第二个活动的一部分.基本上此代码显示手机SD卡中的视频缩略图.无论如何,当我点击缩略图时,我希望列表中的项目被点击打开到下面发布的新活动,这是一个VIEwVIEw.

public class Editor extends Activity {Imagebutton vIDeo1;int isClicked = 0;Imagebutton audio;int isClicked1 = 0;private String path = "mnt/sdcard-ext";private VIDeoVIEw mVIDeoVIEw;    @OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    // Todo auto-generated method stub    super.onCreate(savedInstanceState);    getwindow().setFormat(PixelFormat.TRANSLUCENT);    setContentVIEw(R.layout.editor);    mVIDeoVIEw = (VIDeoVIEw) findVIEwByID(R.ID.vIDeoVIEw);    int data = getIntent().getExtras("mnt/sdcard-ext") .getInt("com.ave.EDITOR");    if (path == "mnt/sdcard-ext") {        // Tell the user to provIDe a media file URL/path.        Toast.makeText(                Editor.this,                "Please edit VIDeoVIEwDemo Activity, and set path"                        + " variable to your media file URL/path",                Toast.LENGTH_LONG).show();    } else {        /*         * Alternatively,for streaming media you can use         * mVIDeoVIEw.setVIDeoURI(Uri.parse(URLstring));         */        mVIDeoVIEw.setVIDeoPath(path);        mVIDeoVIEw.setMediaController(new MediaController(this));        mVIDeoVIEw.requestFocus();    vIDeo1 = (Imagebutton) findVIEwByID(R.ID.vIDeo1);    vIDeo1.setonClickListener(new OnClickListener() {        public voID onClick(VIEw v) {            if (isClicked == 0) {                vIDeo1.setimageResource(R.drawable.vIDeo_pressed);                isClicked = 1;            } else {                vIDeo1.setimageResource(R.drawable.vIDeo1);                isClicked = 0;            }          }     });    audio = (Imagebutton) findVIEwByID(R.ID.audio);    audio.setonClickListener(new OnClickListener() {        public voID onClick(VIEw v) {            if (isClicked1 == 0) {                audio.setimageResource(R.drawable.audio_pressed);                isClicked1 = 1;            } else {                audio.setimageResource(R.drawable.audio);                isClicked1 = 0;            }          }      });    }  }}

正如你所看到的,我不知道如何正确传递意图附加内容,也不知道如何从第3次活动中获取它们.所有帮助表示赞赏.谢谢.

====== AndroID Manifest ======(这不是完整的清单文件)

<activity androID:name=".Menus" androID:label="@string/app_name" androID:screenorIEntation="landscape" >      <intent-filter>            <action androID:name="com.ave.CLEARSCREEN" />            <category androID:name="androID.intent.category.DEFAulT" />      </intent-filter></activity><activity androID:name=".Editor" androID:screenorIEntation="landscape" >      <intent-filter>            <action androID:name="com.ave.EDITOR" />            <category androID:name="androID.intent.category.DEFAulT" />      </intent-filter></activity></application></manifest>

解决方法:

Intent i = new Intent("com.ave.EDITOR");i.putExtra("mnt/sdcard-ext", _ID);startActivity(i);

在onCreate方法中的第二个活动:

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

总结

以上是内存溢出为你收集整理的android – 如何传递Intent Extras?全部内容,希望文章能够帮你解决android – 如何传递Intent Extras?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1099115.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存