Ok, I called it reverse since I am now able to detect a Java class from 
native code without having to do a System.load(nativelib.so) from the Java 
code. Let me try to explain my usage:

1. I have nativelib.so that is loaded & running from where I need to launch 
a 3rd party app. Right now, I'm doing it using 'am' but want to replace 
this by calling a Java method which uses Intent/startActivity
2. Since nativelib.so is already loaded, I can't do System.load () from the 
Java app as there'll be 2 versions of the library. Hence, I want to call 
into the Java method directly from nativelib.so
3. To this effect, I created a .jar (which has the Intent/startActivity 
calls) and was able to find this class from nativelib.so. But, not able to 
call into this method since the .jar is not running

Ok, I could try using JNI functions to start the activity but would like to 
get the above scheme working

On Thursday, July 19, 2012 10:48:53 AM UTC-7, Dianne Hackborn wrote:
>
> On Thu, Jul 19, 2012 at 9:49 AM, HV <[email protected]> wrote:
>
>> The native code is in a library that is already loaded & running. So, I 
>> need something like "reverse" JNI (calling a Java method from C++).
>
>
> That is not "reverse" JNI, that is a basic part of JNI.
>  
>
>> I was able to create a .jar file (which has the Intent call to launch 3rd 
>> party apps), putting it in the CLASSPATH in init.rc & FindClass/GetMethodID 
>> do succeed now. 
>
>
> Er...  what?!?
>
> I so don't understand.  You have your app, which must have Java code on 
> it.  You have your native code.  Use JNI to call the Java code.  If you 
> need some implementation in Java, put it in your Java code.
>
> Hell, if you just want to start an activity, you wouldn't even need any 
> Java code (I just think it is easier to write that part in Java), you can 
> write JNI that creates an Intent object and calls the methods to set it up, 
> and then calls startActivity on the Context.  You do need to pass in the 
> Context (which here will be your Activity object) at some point to your 
> native code...  but you made your native code run, so you called it at some 
> point, so you can do that.
>
> If you are using NativeActivity and so have not written any Java code (so 
> have the illusion of a "pure native" application), the native activity C 
> data structures include the Activity object which you can use to do the 
> startActivity call.  Also you can change your app to have some Java code 
> which implements a subclass of NativeActivity which is the thing that gets 
> run.  Then you can put your Java code there.
>
> Also I would suggest going and looking at android-ndk, because this is 
> basic stuff that people talk about doing when developing with the NDK.
>  
>
>> The issue is with CallVoidMethod which is failing since the .jar file is 
>> not running (unlike the earlier case where in I had a .apk which had an 
>> icon on the desktop that i could just launch easily). Any idea how I can 
>> run the jar file?
>>
>
> Don't.  Put it in your regular app.
>
> -- 
> Dianne Hackborn
> Android framework engineer
> [email protected]
>
> Note: please don't send private questions to me, as I don't have time to 
> provide private support, and so won't reply to such e-mails.  All such 
> questions should be posted on public forums, where I and others can see and 
> answer them.
>
>

-- 
unsubscribe: [email protected]
website: http://groups.google.com/group/android-porting

Reply via email to