• 前台服务


    package com.pingyijinren.test;
    
    import android.annotation.TargetApi;
    import android.app.Notification;
    import android.app.PendingIntent;
    import android.app.Service;
    import android.content.Intent;
    import android.os.Binder;
    import android.os.Build;
    import android.os.IBinder;
    import android.util.Log;
    
    public class MyService extends Service {
        private DownloadBinder downloadBinder=new DownloadBinder();
        public MyService() {
        }
    
        @Override
        public IBinder onBind(Intent intent) {
            // TODO: Return the communication channel to the service.
            //throw new UnsupportedOperationException("Not yet implemented");
            return downloadBinder;
        }
    
        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
        @Override
        public void onCreate(){
            super.onCreate();
            Log.d("MainActivity","create");
    
            Notification.Builder notificationBuilder=new Notification.Builder(this);
            notificationBuilder.setContentTitle("叶良辰")
                    .setContentText("我有一百种方法让你呆不下去")
                    .setTicker("收到叶良辰的消息")
                    .setWhen(System.currentTimeMillis())
                    .setSmallIcon(R.mipmap.ic_launcher);
            Notification notification=notificationBuilder.build();
            startForeground(1,notification);
    
        }
    
        @Override
        public int onStartCommand(Intent intent,int flags,int startId){
            Log.d("MainActivity","startCommand");
            return super.onStartCommand(intent,flags,startId);
        }
    
        @Override
        public void onDestroy(){
            super.onDestroy();
            Log.d("MainActivity","destroy");
        }
    
        class DownloadBinder extends Binder {
            public void startDownload(){
                Log.d("MainActivity","startDownload");
            }
    
            public int getProgress(){
                Log.d("MainActivity","getProgress");
                return 0;
            }
        }
    }
  • 相关阅读:
    学会用google吧,,,
    HDU 2120 Ice_cream's world I
    ZOJ 3471 Most Powerful (状压DP)
    POJ 2192 Zipper
    我的闪存汇总
    Python For Delphi更好地协同(续)
    Python For Delphi更好地协同
    官方的正则表达式组件 RegularExpressions : 基本应用(转自万一博客)
    Thread: DataSnap detect disgraceful disconnect
    window7下安装IPython
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5506066.html
Copyright © 2020-2023  润新知