starting service without application
I have a call blocking application. It has 3 files:
- class BlockMyCall e开发者_运维知识库xtends BroadcastReceiver
- class SimpleClass1 extends Service
- PhoneBlock extends Activity
I start "PhoneBlock " Activity to call Service "SimpleClass1", which eventually calls "BlockMyCall" intended to block outbound calls (by setting result to "null").
I want to know if I can run the class1 from service without starting activity. If so, how?
Put a broadcast receiver to READ_PHONE_STATE and on receiving this broadcast ,start the service.
In your AndroidManifest you can specify the receiver to start at boot like this:
<receiver android:name="ProjectMonitorServiceManager"
android:enabled="true"
android:exported="false"
android:label="ProjectMonitorServiceManager">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
I'm not 100% sure that is what your looking to achieve or not.
精彩评论