小编Ami*_*ain的帖子

无法从服务内部调用线程中的runOnUiThread

如果有任何未读的短信然后将其发送到我的网站,然后将其标记为读取以将数据发布到我使用asynctask的网站,我想制作一个每隔20秒检查一次我的短信的服务,当我手动尝试时(通过制作)它工作正常按钮点击类型应用程序)但在侧面服务我不能定义

runOnUiThread(new Runnable() {
            @Override
            public void run() { new MyAsyncTask().execute(sender,time,message);}
        });
Run Code Online (Sandbox Code Playgroud)

它无法识别并要求我定义runOnUiThread有没有办法从我在下面代码中调用的地方调用我的asynctask

public class TestService extends Service {

    String sender = null;
    String time = null;
    String message = null;

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onCreate() {
        Toast.makeText(getApplicationContext(), "Service Created", 1).show();
        super.onCreate();
    }

    @Override
    public void onDestroy() {
        Toast.makeText(getApplicationContext(), "Service Destroy", 1).show();
        super.onDestroy();
    }

    @Override
    public int onStartCommand(Intent intent, int …
Run Code Online (Sandbox Code Playgroud)

service android android-asynctask

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

标签 统计

android ×1

android-asynctask ×1

service ×1