我希望當我點擊應用按鈕firstapp時,打開第二個應用程序,因此數據通過了印刷機:我做錯了什麼?與其他應用程序交互:onActivityResult方法未被調用Android
Secondapp被調用,但它打印null。
應用1
package pkg.firstapp;
public class MainActivity extends Activity{
private static final int REQUEST_CODE_START_APP = 12345;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
PackageManager manager = getApplicationContext().getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage("pkg.secondapp");
if (i != null)
{
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.putExtra("key1", "value1");
i.setFlags(0);
setResult(RESULT_OK, i);
startActivityForResult(i, REQUEST_CODE_START_APP);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
我之前讀這篇文章,但什麼是錯我的代碼。 – GiGa