I have two Applications, A and B, both applications are made by me but they are in different packages. I want to extract some data from my Activity B to my Activity A.
For this I use ActivityA.startactivityforresult(ActivityB).
This works ok, up until I need to retrive my data from ActivityB, then I start getting NullpointerExceptions for my getExtra() calls.
ActivityA:
protected void someMethod()
{
Intent intent = getPackageManager().getLaunchIntentForPackage("some.package.app");
intent.putExtra("action", "retrieveData");
startActivityForResult(intent, 7854);
}
protected void onActivityResult (int requestCode, int resultCode, Intent intent)
{
Log.d(TAG, "test: " + intent.getExtras().getString("test"));
}
ActivityB:
protected void onResume ()
{
if (getIntent().getExtras() != null && getIntent().getExtras().getString("action").equals("retrieveData"))
{
Intent intent = getIntent();
intent.putExtra("test", "This is a test response");
setResult(7854, intent);
finish();
}
}
OUTPUT: test: null
Am I doing something wrong, or is this simply not allowed?
UPDATE
04-18 18:28:34.908: E/AndroidRuntime(15711): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=7854, result=0, data=null} to activity {dk.rasive.testA/dk.rasive.testA.TestActivity}: java.lang.NullPointerException
04-18 18:32:48.892: E/AndroidRuntime(15801): at dk.rasive.testA.TestActivity.onActivityResult(TestActivity.java:245)
Line 245 contains this code
Log.d(TAG, "test: " + intent.getExtras().getString("test"));
I haven’t tried with Activities in different Applications but Activity A needs to override
Also
takes a ResultCode not a RequestCode although that won’t make a difference in the snippet you posted.
EDIT:
androidmanifest.xml