views:

46

answers:

2

I have a call blocking application. It has 3 files: 1) class BlockMyCall extends BroadcastReceiver 2) class SimpleClass1 extends Service 3) 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?

A: 

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.

Ryan Conrad
A: 

Put a broadcast receiver to READ_PHONE_STATE and on receiving this broadcast ,start the service.

Siddhartho