onActivityResult() : delivering data problem

Put your problem here if it does not fit any of the other categories.

onActivityResult() : delivering data problem

Postby DaminouU » Sat Oct 03, 2009 3:16 pm

Hi,
I am quite a newbie in android programming and I want to transfer information from one activity to another one (which are not in the same apk file).

So, to be clear :
I launch an application called DecisionTreeActivity by this code :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.         Intent i = new Intent(Intent.ACTION_MAIN);
  4.  
  5.         ComponentName toLaunch;
  6.  
  7.         toLaunch = new ComponentName("com.tests.decisionTree", "com.tests.decisionTree.DecisionTreeActivity");
  8.  
  9.  
  10.  
  11.         i.addCategory(Intent.CATEGORY_LAUNCHER);
  12.  
  13.         i.setComponent(toLaunch);
  14.  
  15.         i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
  16.  
  17.         this.startActivityForResult(i, 42);
  18.  
  19.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4

Then, in DecisionTreeActivity, I send the result back with :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.                 Intent i = new Intent();
  3.  
  4.                 i.putExtra("decision", outputToReturn);
  5.  
  6.                 setResult(RESULT_FIRST_USER, i);
  7.  
  8.  
  9.  
  10.                 this.finish();
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Here is my onActivityResult(int requestCode, int resultCode, Intent
data) function. Everything is working fine when these activities are
in the same apk file but when I have to put them into two separate apk
files, it isn't working anymore.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. onActivityResult(int requestCode, int resultCode, Intent data) {
  2.  
  3.         super.onActivityResult(requestCode, resultCode, data);
  4.  
  5.         System.out.println(requestCode + "  " + resultCode);
  6.  
  7.         if(requestCode == 42) {
  8.  
  9.                 String s = (String) data.getStringExtra("decision");
  10.  
  11.                 System.out.println(" Decision: " + s);
  12.  
  13.         }
  14.  
  15.     }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


When onActivityResult is "called", I have those exceptions thrown :

10-03 15:41:16.841: ERROR/vold(31): Unable to lookup media '/devices/platform/msm_sdcc.1/mmc_host/mmc0/mmc0:0001'
10-03 15:41:16.841: ERROR/vold(31): Error processing uevent msg (No such file or directory)
10-03 15:41:24.311: ERROR/vold(31): Unable to lookup media '/devices/platform/msm_sdcc.1/mmc_host/mmc0/mmc0:0001'
10-03 15:41:24.311: ERROR/vold(31): Error processing uevent msg (No such file or directory)
10-03 15:41:32.211: ERROR/AndroidRuntime(1452): Uncaught handler: thread main exiting due to uncaught exception
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=42, result=0, data=null} to activity {com.tests.profiling/com.tests.essai.ModelApplyActivity}: java.lang.NullPointerException
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at android.app.ActivityThread.deliverResults(ActivityThread.java:3005)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3047)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at android.app.ActivityThread.access$2300(ActivityThread.java:112)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1721)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at android.os.Handler.dispatchMessage(Handler.java:99)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at android.os.Looper.loop(Looper.java:123)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at android.app.ActivityThread.main(ActivityThread.java:3948)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at java.lang.reflect.Method.invokeNative(Native Method)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at java.lang.reflect.Method.invoke(Method.java:521)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at dalvik.system.NativeStart.main(Native Method)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): Caused by: java.lang.NullPointerException
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at com.tests.essai.ModelApplyActivity.onActivityResult(ModelApplyActivity.java:192)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at android.app.Activity.dispatchActivityResult(Activity.java:3595)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): at android.app.ActivityThread.deliverResults(ActivityThread.java:3001)
10-03 15:41:32.321: ERROR/AndroidRuntime(1452): ... 11 more
10-03 15:41:32.381: ERROR/vold(31): Unable to lookup media '/devices/platform/msm_sdcc.1/mmc_host/mmc0/mmc0:0001'
10-03 15:41:32.381: ERROR/vold(31): Error processing uevent msg (No such file or directory)


I really don't understand what the problem is. What changes when I associated these two activities with different apk files.

Note that the important line is :
10-03 15:41:32.321: ERROR/AndroidRuntime(1452):java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=42, result=0, data=null} to activity
There we can read that the intent is null (that is really not normal !!)

Could you help me ?

Thanks,

Regards,

DaminouU
DaminouU
Freshman
Freshman
 
Posts: 2
Joined: Sat Oct 03, 2009 3:07 pm

Top

Postby DaminouU » Sat Oct 03, 2009 5:32 pm

I found an answer alone.

Apparently onActivityResult does not work in this kind of situation. So i tried another way to send data : broadcastReceiver.

With a broadcastReceiver in the launching class, I can send it some data when I want from any other applications. It seems to work fine.
DaminouU
Freshman
Freshman
 
Posts: 2
Joined: Sat Oct 03, 2009 3:07 pm

Re: onActivityResult() : delivering data problem

Postby hasitharandika » Mon Jun 07, 2010 8:26 am

hi DaminouU,
could u please tell me hw did u do this?
i'm also getting the same error??

regards,
Mike
hasitharandika
Developer
Developer
 
Posts: 45
Joined: Mon Feb 15, 2010 8:37 am
Location: Sri Lanka

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 17 guests