小编Vin*_*oth的帖子

持续在后台运行服务

持续在后台运行服务.例如,必须启动服务,即使应用程序关闭,也会显示20秒的Toast消息.

public class AppService extends IntentService {

    public int onStartCommand(Intent intent, int flags, int startId) {
        return START_STICKY;
    }

    public AppService() {
        super("AppService");
    }

    @Override
    protected void onHandleIntent(Intent workIntent) {
        Toast.makeText(getApplicationContext(), "hai", Toast.LENGTH_SHORT).show();
        SystemClock.sleep(20000);
    }
}
Run Code Online (Sandbox Code Playgroud)

android android-intentservice

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-intentservice ×1