开发者

Run external background service with intent

Currently I have a blank service, which will eventually be used to determine if a licence has been purchased, this service is in an external app which its only job is to check, and verify the licence (external app: com.example.myapp.licence, main app: com.example.myapp)

com.example.myapp.licence > LicenceService.java:

public class LicenceService extends Service {

   @Override
   public IBinder onBind(Intent intent) {
      return null;
   }

   @Override
   public void onCreate() {

   }

   @Override
   public void onStart(Intent intent, int startid) {

   }
}

com.example.myapp.licence > AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.myapp.licence"
      android:sharedUserId="com.example.myapp"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".My3DroidPaidLicenceActivity"
                  android:label="@string/app_name">
        </activity>
    <service android:enabled="true" android:name=".LicenceService" />
    </application>
</manifest>

but this service force-closes when called with the following from within my main app...

com.example.myapp > MainActivity.java:

 Intent intent = new Intent();
    intent.setClassName("com.example.myapp.licence", "com.example.myapp.licence.LicenceService");

    List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
开发者_运维知识库
    if (list.size() > 0) {
        startActivity(intent);
    }

Can anyone please suggest why this is?

(my apologies if i have not explained anything very well)


Replace

    List<ResolveInfo> list = getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);

if (list.size() > 0) {
    startActivity(intent);
}

with

startService( intent );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜