Horje
android run background service on startup Code Example
android run background service on startup
//AndroidManifest.xml:
 <receiver android:name=".BootBroadcastReceiver" >   
            <intent-filter>   
                <action android:name="android.intent.action.BOOT_COMPLETED" />   
            </intent-filter>   
        </receiver> 
//


//Add permission in your AndroidManifest.xml as:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">
</uses-permission>

//In code part BootBroadcastReceiver:
public class BootBroadcastReceiver extends BroadcastReceiver {     
    static final String ACTION = "android.intent.action.BOOT_COMPLETED";   
    @Override   
    public void onReceive(Context context, Intent intent) {   
        // BOOT_COMPLETED” start Service    
        if (intent.getAction().equals(ACTION)) {   
            //Service    
            Intent serviceIntent = new Intent(context, StartOnBootService.class);       
            context.startService(serviceIntent);   
        }   
    }    
}   
/*
if you are talking about device screen on/off then you need to register <action android:name="android.intent.action.USER_PRESENT" /> and <action android:name="android.intent.action.SCREEN_ON" /> for starting your service when user is present or screen is on.
*/




Java

Related
random number generator java with range Code Example random number generator java with range Code Example
remoce last character froma java string Code Example remoce last character froma java string Code Example
in place transpose in a matrix in java Code Example in place transpose in a matrix in java Code Example
border bottom android xml Code Example border bottom android xml Code Example
read a file in java and store as integer array using buffered reader Code Example read a file in java and store as integer array using buffered reader Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7