我嘗試運行此代碼以從我的數據庫中獲取用戶的狀態。該過程包含JSON,因此我創建了一個新的類來實現Runnable作爲後臺服務。我確實創建了一個類extends Service。在該服務中,我稱之爲線程。我使用處理程序並使用postDelayed重複該線程。 public int onStartCommand(Intent intent, int flags, final int startId)
我使用handler.postDelayed()方法重複任務與時間延遲..這是我的代碼; final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void run()
try
{
//got input from asset that's not a problem
JSONObject obj = new JSONObject(loadJSONFromAsset());
JSONArray m_jArry1 = obj.getJSONArray("check");
int j=0,i,k=0;