Giter Site home page Giter Site logo

004_tutorial_launch_after_boot's Introduction

004_Tutorial_launch_after_boot

Purpose

Tutorial: run my activity on boot remark: it is not necessary to run an activity, e.g. setting up an alarm, or other receiver

2016.10.08. by Szőke Sándor Android Studio version: 2.2 (September 15, 2016)

Steps needed

  • create application
  • change the label text to whaterev you like
  • set the permission in AndroidManifest.xml as follows
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
  • add the boot_completed intent in AndroidManifest.xml:
<receiver android:name=".BootReciever">
    <intent-filter >
        <action android:name="android.intent.action.BOOT_COMPLETED"/>
    </intent-filter>
</receiver>
  • add the following code to a new class BootReciever:
public class BootReciever extends BroadcastReceiver
{

    @Override
    public void onReceive(Context context, Intent intent)
    {

        if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
        {
            // TODO: 2016.10.08. Maybe other activiti need to be carried out than simply run your application 
            
            Intent i = new Intent(context, MainActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }
    }
}
  • switch to class BootReciever
  • apply ALT+ENTER to extentend includes after the following words
    • BroadcastReceiver
    • Context
    • Intent
  • exetute and reboot, your application will be started upon next boot

004_tutorial_launch_after_boot's People

Contributors

szokesandor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.