I'm working on an AIR Native Extension that needs to start a Background Service.
I've tried different methods of starting the service.
Here is my AIR Android Manifest Section (from my -app.xml file)
//AIR android manifest section
<manifest android:installLocation="auto">
<application>
<activity android:name=".TestActivity">
<intent-filter>
<action android:name=".TestActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<service android:name=".TestService">
<intent-filter>
<action android:name="test.default.service"/>
</intent-filter>
</service>
</application>
</manifest>
The Service Class is in the same package as the Activity. The Activity runs just fine, and in the onStart() method of the Activity, i've tried starting the Service with the following Methods:
Method 1:
import android.app.Activity;
public class TestActivity extends Activity
{
@Override
protected void onStart()
{
super.onStart();
Intent intent = new Intent("test.default.service");
//clearly the classes are available because this compiles!
intent.setClass(TestActivity.this, TestService.class);
startService(intent);
}
}
Result:
Unable to start service Intent { act=test.default.service cmp=air.com.my.company/com.my.company.TestService } U=0: not found
Method 2:
import android.app.Activity;
public class TestActivity extends Activity
{
@Override
protected void onStart()
{
super.onStart();
//start a service with intent
startService(new Intent("test.default.service"));
}
}
Result:
FATAL EXCEPTION: main
java.lang.RuntimeExeption: Unable to instantiate service air.com.my.company.TestService:
java.lang.ClassNotFoundException:
Didn't find class "air.com.my.company.TestService" on path: /data/app/air.com.my.company-1.apk
The issue seems to be that "air." is being prefixed to the package name when attempting to start the service. How can I get around this mangling of the package name when running my own custom services?
I've been all over stack overflow, as well as Adobe's forums and can't seem to find a full solution to this problem.
There are a few other posts that touch on this topic, but none provide a real running solution with source.
- AIR Native Extension unable to start service intent Android GCM
- Air Native Extensions for Android In-App Billing
I've cut this down to the simplest case I can to ensure there are no extra moving parts that are causing the issue.
Any official information on how an Android Service can be started from an Extension Context running in AIR would be helpful. It seems even Adobe is hush hush about this issue.