start app at boot time

Android Autostart App

Android Autostart App

If we make a security application of android we need to implement start application at boot time functionality using BroadcastReceiver class and add BroadcastReceiver to manifest file like screenshot below.

start-app-boot-time-manifes
start-app-boot-time-manifes

 
So friends today we are going to learn how autostart app at boot or start time.

 

 

To get result restart your android device after install the project.

Full Source code

 

BootTimeActivity.java


 

package com.androidfromhome.startboottime;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;

public class BootTimeActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(R.layout.activity_boot_time);
    }

    
}

 


 

BootBroadcastReceiver.java


 

package com.androidfromhome.util;

import com.androidfromhome.startboottime.BootTimeActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class BootBroadcastReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Intent i = new Intent(context, BootTimeActivity.class);
        
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(i);
        
    }

}


 

 

activity_boot_time.xml


 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/LinearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#A758AB"
        android:gravity="center"
        android:orientation="vertical"
        android:padding="15dp" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:padding="2dp"
            android:text="Android From Home"
            android:textColor="#ffffff"
            android:textSize="22dp"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="16dp"
            android:text="You have install &quot;Android From Home&quot; start application at boot time tutorial source code. To get more tutorial and custom code logon to        &apos;www.androidfromhome.com&apos;"
            android:textColor="#000000"
            android:textSize="20dp" />

    </LinearLayout>

</LinearLayout>

 


 

 

Download Full Source Code

 

Related Post:-

Sqlite database example in android

GridView example in android with Custom layout

how to get the call log details in android

ListView With section header in android example

Leave a Reply

Your email address will not be published. Required fields are marked *

Get Widget