小编Tec*_*eam的帖子

为什么计划中的代码任务执行固定率不起作用?

我试图在android中添加Sheduled Task的功能,以便在我想知道每当用户丢失他的互联网连接之后做一些事情,然后我想做一个警告对话框.所以我使用Sheduled Task Execution来做这件事但是每当我把我的运行代码放在Runnable中时,Task都没有用.

重要的是我在服务类中这样做

代码是

package com.example.sid.marwadishaadi.LoginHistory;

import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
 import android.os.IBinder;
import android.provider.Settings;
   import android.support.v7.app.AlertDialog;
  import android.util.Log;
     import android.widget.Toast;

    import java.util.concurrent.Executors;

   import java.util.concurrent.ScheduledExecutorService;
  import java.util.concurrent.TimeUnit;

     import static com.bumptech.glide.gifdecoder.GifHeaderParser.TAG;

       public class OnClearFromRecentService extends Service {

            @Override
            public IBinder onBind(Intent intent) {
                return null;
            }

            @Override
            public int onStartCommand(Intent intent, int flags, int startId) {
                Log.e("ClearFromRecentService-", "-----------------------------------------Service Started");
                SharedPreferences sharedPreferences=getSharedPreferences("userinfo",MODE_PRIVATE);
                SharedPreferences.Editor edtr=sharedPreferences.edit();
                String id=sharedPreferences.getString("customer_id","");
                Log.e(TAG, "onStartCommand: .........................."+id); …
Run Code Online (Sandbox Code Playgroud)

java android scheduled-tasks

5
推荐指数
1
解决办法
580
查看次数

标签 统计

android ×1

java ×1

scheduled-tasks ×1