10.Android在一个应用中启动另外一个应用
来源:互联网 发布:sql 查询排名的名次 编辑:程序博客网 时间:2024/05/16 15:31
,就是如何在一个应用中通过某个事件,而去启动另外一个已安装的应用。所以愿意和大家分享一下。
为了能让大家更容易理解,我写了一个简单的Demo,我们的程序有俩个按钮,其中一个点击会启动我自己写的应用(一个3D应用为例),而另外一个按钮会启动系统自带的应用(如,日历,闹钟,计算器等等)。这里我一日历为例子。
首先看一下我们的效果图(点击第一个按钮为例):
下面是Demo的详细步骤:
一、新建一个Android工程命名为StartAnotherApplicationDemo
二、修改main.xml布局,代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:orientation
=
"vertical"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
>
<
TextView
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:text
=
"Welcome to Mr Wei's Blog."
/>
<
Button
android:id
=
"@+id/button"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:text
=
"Start Another Application"
/>
<
Button
android:id
=
"@+id/start_calender"
android:layout_width
=
"fill_parent"
android:layout_height
=
"wrap_content"
android:text
=
"Start Calendar"
/>
</
LinearLayout
>
三、修改主程序StartAnotherApplicationDemo.java代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package
com.android.tutor;
import
android.app.Activity;
import
android.content.ComponentName;
import
android.content.Intent;
import
android.os.Bundle;
import
android.view.View;
import
android.widget.Button;
public
class
StartAnotherApplicationDemo
extends
Activity {
private
Button mButton01, mButton02;
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
mButton01 = (Button) findViewById(R.id.button);
mButton02 = (Button) findViewById(R.id.start_calender);
// -----启动我们自身写的程序------------------
mButton01.setOnClickListener(
new
Button.OnClickListener() {
public
void
onClick(View v) {
// -----核心部分----- 前名一个参数是应用程序的包名,后一个是这个应用程序的主Activity名
Intent intent =
new
Intent();
intent.setComponent(
new
ComponentName(
"com.droidnova.android.games.vortex"
,
"com.droidnova.android.games.vortex..Vortex"
));
startActivity(intent);
}
});
// -----启动系统自带的应用程序------------------
mButton02.setOnClickListener(
new
Button.OnClickListener() {
public
void
onClick(View v) {
Intent intent =
new
Intent();
intent.setComponent(
new
ComponentName(
"com.android.calendar"
,
"com.android.calendar.LaunchActivity"
));
startActivity(intent);
}
});
}
}
四、执行,将得到如上效果。
- 10.Android在一个应用中启动另外一个应用
- 在Android中启动另外一个应用
- Android中 一个应用启动另外一个应用一
- Android 一个应用启动另外一个应用
- Android 一个应用启动另外一个应用
- Android中在一个应用中去启动另外一个应用
- Android中在一个应用中去启动另外一个应用
- Android 在一个应用中如何启动另外一个已安装的应用!!!
- Android 在一个应用中如何启动另外一个已安装的应用
- Android 在一个应用中如何启动另外一个已安装的应用
- Android 在一个应用中如何启动另外一个已安装的应用
- Android 在一个应用中如何启动另外一个已安装的应用!!!
- Android 在一个应用中如何启动另外一个已安装的应用!!!
- Android:在一个应用中启动另外一个已安装的应用
- Android 在一个应用中如何启动另外一个已安装的应用!!!
- Android:在一个应用中启动另外一个已安装的应用
- Android 在一个应用中如何启动另外一个已安装的应用!!!
- 在一个应用程序中启动另外一个应用…
- sIEve 调试js内存泄露
- 我的青春里有你的爱 ——《将爱》影评
- 文件的复制
- 空操作NOP指令在ARM和C51的区别
- javascript的闭包
- 10.Android在一个应用中启动另外一个应用
- Python_API_String Services_re.compile
- Android中判断有无可用网络(是否是3G或者WIFI网络)
- sql dbcc memory
- 黑马程序员_学习日记1_有关C#基础知识总结归纳之对象和类型
- base64出现空格的问题
- django, mysqldb遇到的一个问题【closed】
- 最短路径算法:迪杰斯特拉(Dijkstra)和弗罗伊德(Floyd)
- Gesture