• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

With a chain of work, each chain is executed many times and the first is ahead of the second

mcpixel

Newbie
Jul 13, 2019
13
0
Here is the log with logcat:
Code:
08-02 19:54:05.004 118-1352/? I/GraphicBuffer: allocate buffer (w:480 h:800 f:5) err(0)
08-02 19:54:05.005 118-1352/? I/BufferQueue: [com.example.app1/com.example.app1.MainActivity] createGraphicBuffer before(NULL) after(0x41c561b8, handle=0x41c54f88, w=480, h=800, f=5)
08-02 19:54:05.012 12136-12136/com.example.app1 E/tag1: 1564692071288
08-02 19:54:05.012 12136-12136/com.example.app1 E/tag1: 1564692142434
08-02 19:54:05.012 12136-12136/com.example.app1 E/tag1: 1564691977054
08-02 19:54:05.012 12136-12136/com.example.app1 E/tag1: 1564692137410
08-02 19:54:05.013 12136-12136/com.example.app1 E/tag1: 1564692085695
08-02 19:54:05.013 12136-12136/com.example.app1 E/tag1: 1564692113982
08-02 19:54:05.015 12136-12136/com.example.app1 E/tag1: 1564691972016
08-02 19:54:05.015 12136-12136/com.example.app1 E/tag1: 1564692066231
08-02 19:54:05.015 12136-12136/com.example.app1 E/tag1: 1564692080662
08-02 19:54:05.015 12136-12136/com.example.app1 E/tag1: 1564692108958
08-02 19:54:05.019 118-1352/? I/SurfaceFlinger: [bool android::LayerBase::setFlagsEx(uint32_t, uint32_t)] (com.example.app1/com.example.app1.MainActivity) api:1, flags:0x00000000, mask:0x00000000
08-02 19:54:05.019 118-1352/? W/SurfaceFlinger:     nothing to do with mask 0x00000000
08-02 19:54:05.021 376-407/? I/ActivityManager: [AppLaunch] Displayed Displayed com.example.app1/.MainActivity: +867ms
08-02 19:54:05.027 12136-12136/com.example.app1 E/tag2: 1564692071288
08-02 19:54:05.027 12136-12136/com.example.app1 E/tag2: 1564692142434
08-02 19:54:05.029 12136-12136/com.example.app1 E/tag2: 1564691977054
08-02 19:54:05.031 12136-12136/com.example.app1 E/tag2: 1564692137410
08-02 19:54:05.032 12136-12136/com.example.app1 E/tag2: 1564692085695
08-02 19:54:05.035 12136-12136/com.example.app1 E/tag2: 1564692113982
08-02 19:54:05.035 12136-12136/com.example.app1 E/tag2: 1564691972016
08-02 19:54:05.035 12136-12136/com.example.app1 E/tag2: 1564692066231
08-02 19:54:05.037 12136-12136/com.example.app1 E/tag2: 1564692080662
08-02 19:54:05.037 12136-12136/com.example.app1 E/tag2: 1564692108958
08-02 19:54:05.050 118-118/? I/SurfaceFlinger: [bool android::LayerBase::setFlagsEx(uint32_t, uint32_t)] (Starting com.example.app1) api:2, flags:0x00000000, mask:0x00000000
08-02 19:54:05.050 118-118/? W/SurfaceFlinger:     nothing to do with mask 0x00000000
08-02 19:54:05.053 118-392/? I/BufferQueue: [Starting com.example.app1] disconnect: api=2
08-02 19:54:05.054 118-392/? I/SurfaceTexture: [Starting com.example.app1] [virtual void android::SurfaceTexture::onBuffersReleased()] mCurrentTexture:0, mCurrentBuf:0x41c4dae8
08-02 19:54:05.054 118-392/? I/BufferQueue: [Starting com.example.app1] getReleasedBuffers: returning mask 0xffffffff
08-02 19:54:05.064 118-219/? I/BufferQueue: [Starting com.example.app1] consumerDisconnect
08-02 19:54:05.064 118-219/? I/BufferQueue: [Starting com.example.app1] ~BufferQueue
08-02 19:54:05.069 118-10991/? I/GraphicBuffer: allocate buffer (w:480 h:800 f:5) err(0)
08-02 19:54:05.070 118-10991/? I/BufferQueue: [com.example.app1/com.example.app1.MainActivity] createGraphicBuffer before(NULL) after(0x41c567d8, handle=0x41c44b10, w=480, h=800, f=5)
08-02 19:54:05.582 459-459/? I/SurfaceTextureClient: [0x536b7260] frames:2, duration:1.507000, fps:1.327120
08-02 19:54:05.685 376-406/? I/AlarmManager: reset poweroff alarm none
08-02 19:54:05.712 12136-12156/com.example.app1 E/APP: doWork
08-02 19:54:05.721 12136-12150/com.example.app1 I/WM-WorkerWrapper: Worker result SUCCESS for Work [ id=8cba8fd0-795f-4834-882e-e42a84f2ffd9, tags={ com.example.app1.UploadWorker, tag1, tag2 } ]
08-02 19:54:05.726 12136-12150/com.example.app1 I/WM-WorkerWrapper: Setting status to enqueued for 38ec5c1e-34da-4106-9623-d71c1cfdab14
08-02 19:54:05.764 12136-12136/com.example.app1 E/tag1: 1564692071288
08-02 19:54:05.765 12136-12136/com.example.app1 E/tag1: 1564692142434
08-02 19:54:05.765 12136-12136/com.example.app1 E/tag1: 1564691977054
08-02 19:54:05.765 12136-12136/com.example.app1 E/tag1: 1564692137410
08-02 19:54:05.766 12136-12136/com.example.app1 E/tag1: 1564692085695
08-02 19:54:05.766 12136-12136/com.example.app1 E/tag1: 1564692113982
08-02 19:54:05.766 12136-12136/com.example.app1 E/tag1: 1564691972016
08-02 19:54:05.766 12136-12136/com.example.app1 E/tag1: 1564692066231
08-02 19:54:05.767 12136-12136/com.example.app1 E/tag1: 1564692080662
08-02 19:54:05.767 12136-12136/com.example.app1 E/tag1: 1564692108958
08-02 19:54:05.797 12136-12136/com.example.app1 E/tag2: 1564692071288
08-02 19:54:05.797 12136-12136/com.example.app1 E/tag2: 1564692142434
08-02 19:54:05.798 12136-12136/com.example.app1 E/tag2: 1564691977054
08-02 19:54:05.798 12136-12136/com.example.app1 E/tag2: 1564692137410
08-02 19:54:05.798 12136-12136/com.example.app1 E/tag2: 1564692085695
08-02 19:54:05.798 12136-12136/com.example.app1 E/tag2: 1564692113982
08-02 19:54:05.798 12136-12136/com.example.app1 E/tag2: 1564764845710
08-02 19:54:05.798 12136-12136/com.example.app1 E/tag2: 1564691972016
08-02 19:54:05.798 12136-12136/com.example.app1 E/tag2: 1564692066231
08-02 19:54:05.798 12136-12136/com.example.app1 E/tag2: 1564692080662
08-02 19:54:05.798 12136-12136/com.example.app1 E/tag2: 1564692108958
08-02 19:54:05.799 12136-12136/com.example.app1 E/tag1: 1564692071288
08-02 19:54:05.799 12136-12136/com.example.app1 E/tag1: 1564692142434
08-02 19:54:05.799 12136-12136/com.example.app1 E/tag1: 1564691977054
08-02 19:54:05.799 12136-12136/com.example.app1 E/tag1: 1564692137410
08-02 19:54:05.799 12136-12136/com.example.app1 E/tag1: 1564692085695
08-02 19:54:05.799 12136-12136/com.example.app1 E/tag1: 1564692113982
08-02 19:54:05.799 12136-12136/com.example.app1 E/tag1: 1564764845710
08-02 19:54:05.800 12136-12136/com.example.app1 E/tag1: 1564691972016
08-02 19:54:05.800 12136-12136/com.example.app1 E/tag1: 1564692066231
08-02 19:54:05.800 12136-12136/com.example.app1 E/tag1: 1564692080662
08-02 19:54:05.800 12136-12136/com.example.app1 E/tag1: 1564692108958
08-02 19:54:05.827 118-219/? I/SurfaceFlinger: [SurfaceFlinger] frames:7, duration:1.004000, fps:6.967839
08-02 19:54:07.090 459-459/? I/SurfaceTextureClient: [0x536b7260] frames:2, duration:1.507000, fps:1.327123
08-02 19:54:07.106 118-219/? I/SurfaceFlinger: [SurfaceFlinger] frames:2, duration:1.278000, fps:1.564302
08-02 19:54:07.997 376-391/? I/KeyguardUpdateMonitor: ACTION_BATTERY_CHANGED, status=2,plugged=2, level=78, health=2
08-02 19:54:08.597 459-459/? I/SurfaceTextureClient: [0x536b7260] frames:2, duration:1.506000, fps:1.327154
08-02 19:54:08.613 118-219/? I/SurfaceFlinger: [SurfaceFlinger] frames:2, duration:1.507000, fps:1.327119
08-02 19:54:09.138 459-459/? I/StateTracker: com.android.systemui.statusbar.toolbar.QuickOperationItemPanel$AirlineModeStateTracker@41687828setImageViewResources state is 0
08-02 19:54:09.138 459-459/? I/StateTracker: com.android.systemui.statusbar.toolbar.QuickOperationItemPanel$AirlineModeStateTracker@41687828 mIsUserSwitching is false
08-02 19:54:09.139 459-459/? I/StateTracker: com.android.systemui.statusbar.toolbar.QuickOperationItemPanel$AirlineModeStateTracker@41687828 mIsUserSwitching is false
08-02 19:54:09.139 459-459/? I/StateTracker: com.android.systemui.statusbar.toolbar.ConnectionSwitchPanel$AirlineModeStateTracker@416a0978setImageViewResources state is 0
08-02 19:54:09.140 459-459/? I/StateTracker: com.android.systemui.statusbar.toolbar.ConnectionSwitchPanel$AirlineModeStateTracker@416a0978 mIsUserSwitching is false
08-02 19:54:09.147 459-459/? I/StateTracker: com.android.systemui.statusbar.toolbar.ConnectionSwitchPanel$AirlineModeStateTracker@416a0978 mIsUserSwitching is false
08-02 19:54:09.147 376-788/? E/CellLocation: create GsmCellLocation
08-02 19:54:09.150 376-391/? E/CellLocation: create GsmCellLocation
08-02 19:54:09.153 376-391/? E/CellLocation: create GsmCellLocation
08-02 19:54:09.156 523-523/? I/CallNotifier: PhoneStateListener.onServiceStateChanged: serviceState=SIM1 0 home Tele2 Tele2 25020  HSPA CSS not supported -1 -1 RoamInd=-1 DefRoamInd=-1 EmergOnly=false Regist state: 1
08-02 19:54:09.433 129-129/? W/MtkAgps: ** mtk_agps_update_cinfo(): imsi(250207413982106) mcc(250) mnc(20) lac(27874) cid(3454224)**
08-02 19:54:09.433 129-129/? W/MtkAgps:    -> update cell info: mcc(250)->(250) mnc(20)->(20) lac(27874)->(27874) cid(3454223)->(3454224)
08-02 19:54:09.433 129-129/? I/MtkAgps:      -> update supl_p: mcc(250) mnc(20) ucid(3454224), status(1)
08-02 19:54:10.104 459-459/? I/SurfaceTextureClient: [0x536b7260] frames:2, duration:1.507000, fps:1.327078
08-02 19:54:10.120 118-219/? I/SurfaceFlinger: [SurfaceFlinger] frames:2, duration:1.507000, fps:1.327004
08-02 19:54:10.724 376-406/? I/AlarmManager: reset poweroff alarm none
08-02 19:54:10.762 12136-12136/com.example.app1 E/tag1: 1564692071288
08-02 19:54:10.763 12136-12136/com.example.app1 E/tag1: 1564692142434
08-02 19:54:10.763 12136-12136/com.example.app1 E/tag1: 1564691977054
08-02 19:54:10.764 12136-12136/com.example.app1 E/tag1: 1564692137410
08-02 19:54:10.764 12136-12136/com.example.app1 E/tag1: 1564692085695
08-02 19:54:10.765 12136-12136/com.example.app1 E/tag1: 1564692113982
08-02 19:54:10.765 12136-12136/com.example.app1 E/tag1: 1564764845710
08-02 19:54:10.765 12136-12136/com.example.app1 E/tag1: 1564691972016
08-02 19:54:10.766 12136-12136/com.example.app1 E/tag1: 1564692066231
08-02 19:54:10.766 12136-12136/com.example.app1 E/tag1: 1564692080662
08-02 19:54:10.767 12136-12136/com.example.app1 E/tag1: 1564692108958
08-02 19:54:10.769 12136-12160/com.example.app1 E/APP: doWork
08-02 19:54:10.771 12136-12150/com.example.app1 I/WM-WorkerWrapper: Worker result SUCCESS for Work [ id=38ec5c1e-34da-4106-9623-d71c1cfdab14, tags={ com.example.app1.UploadWorker, tag1, tag2 } ]
08-02 19:54:10.776 12136-12136/com.example.app1 I/SurfaceTextureClient: [0x51df76e0] frames:5, duration:5.797000, fps:0.862438
08-02 19:54:10.856 12136-12136/com.example.app1 E/tag2: 1564692071288
08-02 19:54:10.856 12136-12136/com.example.app1 E/tag2: 1564692142434
08-02 19:54:10.857 12136-12136/com.example.app1 E/tag2: 1564764850767
08-02 19:54:10.857 12136-12136/com.example.app1 E/tag2: 1564691977054
08-02 19:54:10.858 12136-12136/com.example.app1 E/tag2: 1564692137410
08-02 19:54:10.858 12136-12136/com.example.app1 E/tag2: 1564692085695
08-02 19:54:10.858 12136-12136/com.example.app1 E/tag2: 1564692113982
08-02 19:54:10.859 12136-12136/com.example.app1 E/tag2: 1564764845710
08-02 19:54:10.859 12136-12136/com.example.app1 E/tag2: 1564691972016
08-02 19:54:10.860 12136-12136/com.example.app1 E/tag2: 1564692066231
08-02 19:54:10.860 12136-12136/com.example.app1 E/tag2: 1564692080662
08-02 19:54:10.861 12136-12136/com.example.app1 E/tag2: 1564692108958
08-02 19:54:10.910 12136-12136/com.example.app1 E/tag1: 1564692071288
08-02 19:54:10.911 12136-12136/com.example.app1 E/tag1: 1564692142434
08-02 19:54:10.911 12136-12136/com.example.app1 E/tag1: 1564764850767
08-02 19:54:10.912 12136-12136/com.example.app1 E/tag1: 1564691977054
08-02 19:54:10.912 12136-12136/com.example.app1 E/tag1: 1564692137410
08-02 19:54:10.913 12136-12136/com.example.app1 E/tag1: 1564692085695
08-02 19:54:10.913 12136-12136/com.example.app1 E/tag1: 1564692113982
08-02 19:54:10.914 12136-12136/com.example.app1 E/tag1: 1564764845710
08-02 19:54:10.914 12136-12136/com.example.app1 E/tag1: 1564691972016
08-02 19:54:10.914 12136-12136/com.example.app1 E/tag1: 1564692066231
08-02 19:54:10.915 12136-12136/com.example.app1 E/tag1: 1564692080662
08-02 19:54:10.915 12136-12136/com.example.app1 E/tag1: 1564692108958
08-02 19:54:11.611 459-459/? I/SurfaceTextureClient: [0x536b7260] frames:2, duration:1.507000, fps:1.327068
08-02 19:54:11.627 118-219/? I/SurfaceFlinger: [SurfaceFlinger] frames:5, duration:1.506000, fps:3.317970
08-02 19:54:13.118 459-459/? I/SurfaceTextureClient: [0x536b7260] frames:2, duration:1.507000, fps:1.327095
08-02 19:54:13.134 118-219/? I/SurfaceFlinger: [SurfaceFlinger] frames:2, duration:1.507000, fps:1.327057
08-02 19:54:14.627 459-459/? I/SurfaceTextureClient: [0x536b7260] frames:2, duration:1.509000, fps:1.325255
08-02 19:54:14.641 118-219/? I/SurfaceFlinger: [SurfaceFlinger] frames:2, duration:1.507000, fps:1.327107
08-02 19:54:14.737 376-413/? I/InputReader: Reconfiguring input devices.  changes=0x00000010
08-02 19:54:14.749 376-393/? I/ActivityManager: Start proc android.process.acore for broadcast com.android.providers.contacts/.PackageIntentReceiver: pid=12161 uid=10060 gids={3003, 1015, 1028}
08-02 19:54:14.780 12161-12161/? E/Trace: error opening trace file: No such file or directory (2)
08-02 19:54:14.786 562-562/? I/Launcher: setLoadOnResume
08-02 19:54:14.802 12161-12161/? I/ActivityThread: Pub com.android.voicemail: com.android.providers.contacts.VoicemailContentProvider
08-02 19:54:14.848 11639-11639/? I/AccountTypeManager: Received Intent:Intent { act=android.intent.action.PACKAGE_CHANGED dat=package:com.example.app1 flg=0x8000010 (has extras) }
08-02 19:54:14.848 11639-11657/? I/AccountTypeManager: loadAccountsInBackground()+
Code in MainActivity:
Java:
TextView [text = findViewById(R.id.text);

		Constraints constraints = new Constraints.Builder().setRequiresCharging(true).build();
		Data data = new Data.Builder().putString(KEY_NAME, "Mike").build();
		OneTimeWorkRequest.Builder uploadWordRequest = new OneTimeWorkRequest.Builder(UploadWorker.class)
				.setConstraints(constraints)
				.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 5, TimeUnit.SECONDS)
				.setInputData(data)
				.keepResultsForAtLeast(2, TimeUnit.SECONDS);

		OneTimeWorkRequest one = uploadWordRequest.setInitialDelay(1, TimeUnit.SECONDS).addTag("tag1").build();
		OneTimeWorkRequest two = uploadWordRequest.setInitialDelay(5, TimeUnit.SECONDS).addTag("tag2").build();

		WorkManager w = WorkManager.getInstance(getApplicationContext());
		w.beginWith(one).then(two).enqueue();

		LiveData<List<WorkInfo>> l = w.getWorkInfosByTagLiveData("tag1");
		l.observe(this, new Observer<List<WorkInfo>>() {
			@SuppressLint("SetTextI18n")
			@Override
			public void onChanged(List<WorkInfo> workInfos) {
				for(int i=0;i<workInfos.size(); i++) {
					if(workInfos.get(i).getState() == WorkInfo.State.SUCCEEDED) {
						text.setText("" + workInfos.get(i).getOutputData().getLong(KEY_NAME, 0));
						Log.e("tag1", "" + workInfos.get(i).getOutputData().getLong(KEY_NAME, 0));
					}
				}
			}
		});
		w.getWorkInfosByTagLiveData("tag2").observe(this, new Observer<List<WorkInfo>>() {
			@SuppressLint("SetTextI18n")
			@Override
			public void onChanged(List<WorkInfo> workInfos) {
				for(int i=0;i<workInfos.size(); i++) {
					if(workInfos.get(i).getState() == WorkInfo.State.SUCCEEDED) {
						text.setText("" + workInfos.get(i).getOutputData().getLong(KEY_NAME, 0));
						Log.e("tag2", "" + workInfos.get(i).getOutputData().getLong(KEY_NAME, 0));
					}
				}
			}
		});
UploadWorker.java:
Java:
package com.example.app1;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.Data;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

public class UploadWorker extends Worker {

	public UploadWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
		super(context, workerParams);
	}

	@NonNull
	@Override
	public Result doWork() {
		String key = "string1";
		Data ret = new Data.Builder().putLong(key, System.currentTimeMillis()).build();
		Log.e("APP", "doWork");
		return Result.success(ret);
	}
}
Why does the text not change 5 seconds after the application starts? It changes only once and this is not what I need!
You see that tag1 is ahead of tag2 which should not be. It is necessary that after a second the text is updated with the first value, and then after 4 seconds with a different value according to the logic of the code
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones