发现在一个程序里面的各个活动间, 用Intent激活是很容易的,
但再写一个程序来激活之前程序的各个活动就总是说找不到活动了.
谁能说说是什么原因....又或者直接给个成功调用的例子.
但再写一个程序来激活之前程序的各个活动就总是说找不到活动了.
谁能说说是什么原因....又或者直接给个成功调用的例子.
解决方案 »
- 程序的入口Activity问题
- android中自动简体getITelephony(tm).answerRingingCall();不执行,是什么原因,请各位大侠帮忙解决
- android 不同activity中怎么传递参数,又不开启新的activity
- Android 调整非当前页面的背景透明度
- Android MonkeyRunner
- 问个简单的按钮UI问题
- 关于android开发时copy网络代码的习惯
- 基于open street map的地图引擎,支持离线地图。
- 谁能告诉我个eclipse或者myeclipse能装成功android环境的方法
- 把手机的短信读取出来,并显示在电脑
- Mp3中OnResume怎样放回onServiceConnected对象
- 打开 “图库”的时候调用我自己的activity提示输入密码
<intent-filter>
<action android:name="com.example.project.SHOW_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>在StartActivity(it)之前,设定该intent对应的action(com.example.project.SHOW_ACTIVITY)
我敢肯定都是没实际写过 程序A来启动程序B里的一个activity 的例子
ComponentName comp = new ComponentName("包名", "类名");
mIntent.setComponent(comp);
mIntent.setAction("android.intent.action.VIEW");
startActivity(mIntent);
类名为程序的activity,可以给mIntent设置flag,一般是Intent.FLAG_ACTIVITY_NEW_TASK
我是指A和B两个程序都是你写的....
其中B的写法才问题的关键....
而书上通常只说A的写法, 以及在A内部各个活动的之间的激活本以为android学起来会很轻松, 以为照着书上学就对了.
但现在发现每一步都是一个坎, 进展非常缓慢....
android居然连个文件选择对话框都没有, 于是我想写一个,
于是要求能让别人用Intent就能激活我的文件选择器
这就是本贴问题的来源....
等我写好后会共享源码出来, 让后来人不必像我这样一步一个坎走过来....
A程序需要调用B的地方:
Intent mWifiIntent = new Intent(“android.action.view”);//intent里的内容自己定义
mWifiIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(mWifiIntent);B程序的配置文件AndroidManifest.xml,需要启用的activity里添加
<intent-filter>
<action android:name="android.action.view" />
</intent-filter>
这个很关键
http://download.csdn.net/source/3171544
我想无论是参考,还是在测试中需要选择文件,都是有点价值的.本贴的正解是, 活动在AndroidManifest.xml中必须添加属性android:exported="true"
<activity android:name="FileSelector" android:exported="true">
这样才能把活动供给其他应用程序使用.
android:exported
Whether or not components of other applications can launch the target activity
through this alias — "true" if they can, and "false" if not.
If "false", the target activity can be launched through the alias only by
components of the same application as the alias or applications with the same user ID.其他应用程序的组件是否可以通过别名载入目标activity — "true"表示可以,"false"表示不可以。如果"false",目标activity只可以被别名的同一或者拥有相同用户ID的应用程序组件通过别名载入。我的代码里没有加这个也能够调用的
你能把你的例子源码发给我看一下么? [email protected]
showActivity.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent showIntent = new Intent("intent.show.another.activity");
startActivity(showIntent);
}
}); <activity android:name=".main_activity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="intent.show.another.activity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
试了一下不设置 android:exported="true" 也是可以的.
搞不懂当初为什么会不行了...
intent.setClassName(this, "全路径");//包名+类名
startActivity(intent);