• Android学习笔记_70_一个应用程序启动另一个应用程序的Activity


    第一种(我自己写的) :之前在网上看来一些,很多不是我要的可以启动另外一个应用程序的主Activity.

    //这些代码是启动另外的一个应用程序的主Activity,当然也可以启动任意一个Activity
    ComponentName componetName = new ComponentName(
    //这个是另外一个应用程序的包名
    "com.poynt.weibo",
    //这个参数是要启动的Activity
    "com.poynt.weibo.ui.IndexActivity");

    try {
    Intent intent = new Intent();
    intent.setComponent(componetName);
    startActivity(intent);
    } catch (Exception e) {
    // Toast.makeText(getApplicationContext(), "可以在这里提示用户没有找到应用程序,或者是做其他的操作!", 0).show();

    }
    复制代码


    第二种

    :这里是启动另外一个程序的Activity之后,并把参数传过去!
    在一个Android应用程序A中调用另一个Android程序B,同时传递数据给B

    ComponentName componentName = new ComponentName(
    "com.xiaohua.player.activity",
    "com.xiaohua.player.activity.PlayerActivity");
    Intent intent = new Intent();
    Bundle bundle = new Bundle();
    bundle.putString("resUrl", resurl);
    bundle.putSerializable("picUrlList", picurllist);
    intent.putExtras(bundle);
    intent.setComponent(componentName);
    startActivity(intent);
    注:
    com.xiaohua.player.activity:包路径
    PlayerActivity:Activity类
    resUrl :String类型
    picUrlList:数组,也可以是对象
    应用程序安装后,按以上方式可进行调用.


    接受activity:
    public void getParameterByIntent() {
    Intent mIntent = this.getIntent();
    String resUrl = mIntent.getStringExtra("resUrl");
    String[] picUrlList = (String[]) mIntent.getSerializableExtra("picUrlList");
    if (null != picUrlList) {
    int count = picUrlList.length;
    for (int i = 0; i < count; i++) {
    Log.e("tag", "picUrlList[" + i + "]" + picUrlList);
    }
    }
    }

    来自:http://hi.baidu.com/huaxinchang/blog/item/5fa81903474097f409fa9305.html
    复制代码

    第三种:在一个apk中调用另外一个apk中的activity
    转自:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=69600
    其实,这本来是一件很简单的事情,但是小编发现很多人问这个问题,所以写篇小文章供eoe的朋友们参考。

    系统提供了很多可以直接调用的Activity,通过指定的Intent就可以调用,比如打开搜索的:


    Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
    intent.putExtra(SearchManager.QUERY,"searchString")
    startActivity(intent);
    复制代码

    Intent.ACTION_WEB_SEARCH是一个字符串,是“搜索”这个Activity的标识,extra是传给这个activity的一些数据。发送出这个intent之后,系统根据action字符串Intent.ACTION_WEB_SEARCH知道了是要调用哪个activity,如果有重名,会弹出一个选择对话框。然后打开此activity,实现想要做的事情。

    那么,我们自己怎么来实现呢。

    首先,写一个activity,在AndroidManifest.xml里面的intent-filter中,给这个activity命名:


    <intent-filter>
    <action android:name="chroya.foo"/>
    <category android:name="android.intent.category.DEFAULT"/>
    </intent-filter>
    复制代码


    然后安装。安装完毕之后,你会发现,系统中找不到这个程序。别急,它确实安装在手机里面了,但是因为他不是main的,所以系统不会把他当做Application的入口程序。

    而要想打开这个activity,只有知道它名字的人才可以。跟系统的intent一样使用。它的名字定义为"chroya.foo",所以,这里用这个字符串就可以调用它了:

    Intent intent = new Intent("chroya.foo");
    startActivity(intent);
    复制代码

     
  • 相关阅读:
    接口中可以定义内部类举例
    eclipse中项目maven update无法停止解决方法
    tomcat failed to start / could not publish server configuration解决
    导入项目时jsp带红叉,或者实现类提示需要override接口的问题
    常见异常与总结——一句话的描述
    Maven导入shiro的依赖后,欢迎页面404、shiro-features异常的解决方案:
    eclipse解决maven项目右键run as没有run on server的问题:
    SpringCloud搭建教程
    异常:java.lang.IllegalArgumentException: Could not resolve placeholder 'xxx' in value "${xxx}"
    SQL题1——查询所有购入商品为两种或两种以上的购物人记录
  • 原文地址:https://www.cnblogs.com/lbangel/p/3672883.html
Copyright © 2020-2023  润新知