0

Suppose we have an Android APK file which contains only a single BroadcastReceiver. Will this form of the APK file be installed on Android devices be installed successfully and can the BR receive intended intents? I thought it will, but my experiment showed it does not. I am not sure why, but the installation of such APK files (with a single BR) seems to fail all the time.

A solution to this problem is to add a dummy Activity to the package. Then the installation succeeds, and the BroadcastReceiver can receive all intended intents!

Please share your opinion on this matter.

I always thanks you all for helps!

user3509406
  • 389
  • 1
  • 10
  • 1
    Post your code and the error you are seeing. Widgets are receivers and can work fine with no activity at all in your application but I can't tell if you are doing that or not. – Greg Ennis Jun 12 '14 at 10:29
  • Adding a dummy activity, solved the issue. Did you set up this dummy activity in your manifest as launcher? – Parth Kapoor Jun 12 '14 at 10:37
  • The problem I met is that the BroadcastReceiver didn't receive any intents. There is no compilation error here. The intent-filter of the dummy activity is "android.intent.action.MAIN" as an action, and "android.intent.category.LAUNCHER" as a category. There is nothing else other than them in the manifest file for the dummy activity. – user3509406 Jun 12 '14 at 10:47
  • Oh, I should say this. The installation has not been failed, but the BroadcastReceiver hasn't received any intents. Sorry for any confusion from my sloppy English. – user3509406 Jun 12 '14 at 11:07

2 Answers2

0

You need at least one Activity for landing page in the android app. What are you expecting will happen when the app is launched manually?

Green goblin
  • 9,898
  • 13
  • 71
  • 100
0

Will this form of the APK file be installed on Android devices be installed successfully and can the BR receive intended intents?

No.

I am not sure why, but the installation of such APK files (with a single BR) seems to fail all the time.

No, but the BroadcastReceiver will not receive broadcasts until something has directly invoked one of your components via an explicit Intent (i.e., an Intent that identifies the class). Normally, that will happen by the user launching your LAUNCHER activity. This has been the case since Android 3.1, about three years ago (see "Launch controls on stopped applications" in the Android 3.1 release notes).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Great! Your answer is what I expected to see. The link to "Launch controls on stopped applications" looks very valuable tome. Many thanks to you and to the other helpers as well!!! – user3509406 Jun 12 '14 at 11:01