return downloadBinder;

}

@Override

public void onCreate() {

super.onCreate();

Log.d(TAG, "onCreate: ");

Intent intent = new Intent(this,MainActivity.class);

PendingIntent pi = PendingIntent.getActivity(this,0,intent,0);

Notification notification = new Notification.Builder(this)

.setContentTitle(“这是前台服务通知标题”)

.setContentText(“这是前台服务通知内容”)

.setWhen(System.currentTimeMillis())

.setSmallIcon(R.mipmap.ic_launcher_round)

.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))

.setContentIntent(pi)

.build();

startForeground(1,notification);

}

@Override

public int onStartCommand(Intent intent, int flags, int startId) {

Log.d(TAG, "onStartCommand: ");

return super.onStartCommand(intent, flags, startId);

}

@Override

public void onDestroy() {

super.onDestroy();

Log.d(TAG, "onDestroy: ");

}

}

package nopi.aystudio.mthread;

import android.content.ComponentName;

import android.content.Intent;

import android.content.ServiceConnection;

import android.os.IBinder;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

Button button1;

Button btn_canel;

private MyService.DownloadBinder downloadBinder;

private ServiceConnection connection = new ServiceConnection() {

@Override

public void onServiceConnected(ComponentName name, IBinder service) {

downloadBinder = (MyService.DownloadBinder)service;

downloadBinder.getNumber();

downloadBinder.startDownload();

}

@Override

public void onServiceDisconnected(ComponentName name) {

Toast.makeText(MainActivity.this, “失去连接。。。”, Toast.LENGTH_SHORT).show();

}

};

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

button1 = findViewById(R.id.button1);

btn_canel = findViewById(R.id.btn_canel);

button1.setOnClickListener(this);

btn_canel.setOnClickListener(this);

}

学习分享,共勉

Android高级架构师进阶之路

题外话,我在阿里工作多年,深知技术改革和创新的方向,Android开发以其美观、快速、高效、开放等优势迅速俘获人心,但很多Android兴趣爱好者所需的进阶学习资料确实不太系统,完整。今天我把我搜集和整理的这份学习资料分享给有需要的人,若有关Android学习进阶可以与我在Android终极开发交流群一起讨论交流。 点击这里前往我的Git领取资料 的同时,还可以加入一个好的学习交流圈,何乐而不为呢?加入我们和我们一起吧!!

  • Android进阶知识体系学习脑图

  • Android进阶高级工程师学习全套手册

  • 对标Android阿里P7,年薪50w+学习视频

  • 大厂内部Android高频面试题,以及面试经历

级工程师学习全套手册**

[外链图片转存中…(img-wqkd50jS-1643963609634)]

  • 对标Android阿里P7,年薪50w+学习视频

[外链图片转存中…(img-TdaCVTsH-1643963609635)]

  • 大厂内部Android高频面试题,以及面试经历

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐