How to use Service with Juce in Android system


#1

Hi,
I found it difficult to add Service When use Juce. In Juce, we must call launchApp interface to initialize AndroidSystem. This interface need the Activity object to use. If in an Application, we must launch Service first, but we can not call launchApp to initialize. so we should have some other interface to initialize AndroidSystem. How can we resolve this problem?


#2

I’m not much of an Android expert, so not actually sure what you mean by a “service”? If it’s something that you need to do in java, then I guess you’d need to customise the java AppActivity class that the introjucer creates (?)


#3

Thanks. you can read in http://developer.android.com/guide/components/services.html


#4

Well yes, it doesn’t sound like something you’d want to write in C++/JNI, so using your own custom AppActivity class would probably be the way to do that.


#5

The message loop is easy to resolve. The difficult problem is when we initialize AndroidSystem from Service, The android.activity is not evaluated. so we cann’t use the createNewPeer to get object of AndroidComponentPeer . But when we launch AppActivity, how can the ui draw to screen? I think we must re-call createNewPeer to create a AndroidComponentPeer object for all windows that attached to desktop. How can I resolve this problem?


#6

What do you mean by “not evaluated”? The java wrapper code must call AndroidSystem::initialise to set up the activity object - nothing can work until that has been done. You can’t pass a null pointer in there (?)


#7

If we initialize AndroidSystem from Service we cann’t have an activity object, so we should write some interface different form launchApp. And When we launch AppActivity, we should call launchApp to initialize android.activity.


#8

Yes, you’d need to customise it somehow, but I’m really not sure exactly what you’d need to do… Am happy to help if you want to make suggestions, but don’t have time to figure this out for you myself.