JobIntentService的呼叫主动方法

问题描述 投票:0回答:1

我想在onHandleWork内部的for循环中调用一个非静态方法。我该如何实现?

@Override
protected void onHandleWork(@NonNull Intent intent) {
    Log.d(TAG, "onHandleWork");

    String input = intent.getStringExtra("inputExtra");


    for (int i = 0; i < 10; i++) {
        Log.d(TAG, input + " - " + i);

        new MainActivity.method();

        if (isStopped()) return;

        SystemClock.sleep(1000);
    }
}
java android android-studio android-service jobintentservice
1个回答
0
投票

您应该广播一条消息,表明该活动正在监听。

[要实现这一点,请在活动上使用广播接收器,并通过context.sendBroadcast(intent)从作业服务发送它

文档:https://developer.android.com/reference/android/content/BroadcastReceiver

© www.soinside.com 2019 - 2024. All rights reserved.