Android--Boot no GUI daemon

Source: Internet
Author: User

Simply put, this is an app that runs in the background without the interface

Also, there is a function: Boot from start, start running a service


The program structure is very simple, two classes, one is the service extension class, one is the Broadcastreceiver extension class


[Java]View PlainCopyprint?
  1. Import Android.app.Service;
  2. Import android.content.Intent;
  3. Import Android.os.IBinder;
  4. Import Android.util.Log;
  5. Import Android.widget.Toast;
  6. Public class Testservice extends service{
  7. public void OnCreate () {
  8. super.oncreate ();
  9. LOG.D ("aaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaa");
  10. Toast.maketext (Getapplicationcontext (), default toast style,
  11. Toast.length_long). Show ();
  12. }
  13. Public IBinder Onbind (Intent Intent) {
  14. LOG.D ("bbbbbbbbbbbbbbbbbbb", "bbbbbbbbbbbbbbbbbbbbbbb");
  15. Toast.maketext (Getapplicationcontext (), "No default toast Style",
  16. Toast.length_long). Show ();
  17. return null;
  18. }
  19. }

Broadcastreceiver Extension classes:

[Java]View PlainCopyprint?
  1. Import Android.content.BroadcastReceiver;
  2. Import Android.content.Context;
  3. Import android.content.Intent;
  4. Import Android.util.Log;
  5. Public class Bootreceiver extends Broadcastreceiver {
  6. @Override
  7. public void OnReceive (Context arg0, Intent arg1) {
  8. //TODO auto-generated method stub
  9. LOG.D ("wwwwwwwwwwwwwwwwwwwww", "wwwwwwwwwwwwwwwwwwwwwwww");
  10. Intent mbootintent = new Intent (arg0, Testservice.   Class);
  11. Arg0.startservice (mbootintent);
  12. LOG.D ("CCCCCCCCCCCCCCCCCCCCC", "CCCCCCCCCCCCCCCCCCCCCCCC");
  13. }
  14. }

Configuration file:

<?xml version= "1.0" encoding= "Utf-8"?>
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
Package= "Com.tyq"
Android:versioncode= "1"
Android:versionname= "1.0" >

<application
android:icon= "@drawable/ic_launcher"
Android:label= "@string/app_name" >
<service android:name= ". Testservice "></service>
<receiver android:name= ". Bootreceiver ">
<intent-filter>
<action android:name= "Android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
</application>

<uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED"/>
<USES-SDK android:minsdkversion= "Ten"/>
</manifest>

Reference http://netspook.iteye.com/blog/1291236

Attach knowledge about Android broadcasting

http://bk-lin.iteye.com/blog/1569568

Android-Boot without background program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.