在按钮单击时打开另一个应用程序?

时间:2010-07-27 14:47:45

标签: android

我有两个申请。 ApplicationA ApplicationB 。从ApplicationA我必须打开ApplicationB。同时我需要向ApplicationB发送一些细节。如何做到这一点?

2 个答案:

答案 0 :(得分:1)

你可以通过只写一行代码

来做到这一点
Intent mIntent = new Intent(this,"Here second app package name like com.urproject.urclass.class");

对于发送到某些详细信息,意味着您可以使用bundle或sharedpreference或使用类名声明静态和访问。

Bundle extras = mIntent.getExtras();
extras.putString(key, value); 

答案 1 :(得分:0)

第一个上下文(可以是活动/服务等)

您有几个选择:

1)使用Bundle中的Intent

Intent mIntent = new Intent(this, Example.class);
Bundle extras = mIntent.getExtras();
extras.putString(key, value);  

2)创建一个新的Bundle

Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.extras.putString(key, value);
mIntent.putExtras(mBundle);

3)使用Intent的putExtra()快捷方式

Intent mIntent = new Intent(this, Example.class);
mIntent.putExtra(key, value);

新上下文(可以是活动/服务等)

Intent myIntent = getIntent(); // this getter is just for example purpose, can differ
if (myIntent !=null && myIntent.getExtras()!=null)
     String value = myIntent.getExtras().getString(key);
}

注意: Bundles对所有基本类型,Parcelables和Serializables都有“get”和“put”方法。我只是将字符串用于演示目的。

相关问题