当前位置: 代码迷 >> Android >> 怎么打开另一个app并传递一些参数过去
  详细解决方案

怎么打开另一个app并传递一些参数过去

热度:27   发布时间:2016-05-01 11:13:19.0
怎样打开另一个app并传递一些参数过去?
怎样打开另一个app并传递一些参数过去?
app1
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.example.xeednfc");
Bundle bundle = new Bundle();
     bundle.putString("user","1");
     LaunchIntent.putExtras(bundle);
startActivity(LaunchIntent);

app2

protected void onCreate(Bundle savedInstanceState) 
{
super.onCreate(savedInstanceState);
Bundle bunde = getIntent().getExtras();
怎么bundle 一直是空的。接收不到
if(bunde!=null)
{
  bundle.getString("user");

}
}

------解决方案--------------------
contentprivider
------解决方案--------------------
contentprivider
------解决方案--------------------
ContentProvider 你可以网上搜一下  这是Android的四大组件之一
------解决方案--------------------
你这个方法是启动的主activity就是配置main的,这个你控制不了。其他activity就自己在配置文件写个action,然后用这个action打开。打开的不是主界面了
------解决方案--------------------
为什么不用Intent i=new Intent(A.this,B.class)来传递参数呢?
------解决方案--------------------
还是给你写代码
在第一个app里

Intent intent = new Intent("com.ox.lyq.ABCD");
intent.putExtra("abcd", "ABCD");
startActivity(Intent.createChooser(intent, "ABCD"));

在第二个app的AndroidManifest.xml里
 <activity android:name="BActivity" >
            <intent-filter>
                <action android:name="com.ox.lyq.ABCD" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
 </activity>

 <category android:name="android.intent.category.DEFAULT" />
不可少
在这个activity里

textView = (TextView) findViewById(R.id.textView1);
Intent intent = getIntent();
if (intent != null) {
    String str = intent.getStringExtra("abcd");
    textView.setText(str);
}

这绝对是2个app
  相关解决方案