我想回憶一下12分鐘後,誰得到我的JSON時間的活動,但我不知道如何使用timertask和timershedule你能幫我嗎? 我嘗試這一點,但不是工作 我的程序:回想一個活動
public class recuperationJson extends AppCompatActivity implements getData.ReturnValue {
private getData data;
private TextView t;
private String json_string;
private String json_url = "http://192.168.0.14/projet/php/fichier.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
data = new getData(json_url);
data.setReturnListener(this);
data.execute((Void) null);
Timer timer = new Timer();
timer.scheduleAtFixedRate(new Testing(), 0,5000);
}
@Override
public String renvoyerValeurString(String valeurARenvoyer) {
data = null;
//Ici je récupère directement mon json contenu dans la variable valeurARenvoyer
json_string = valeurARenvoyer;
Intent intent = new Intent(this,Accueil.class);
intent.putExtra("json_data", json_string);
startActivity(intent);
// Toast.makeText(this, json_string, Toast.LENGTH_SHORT).show();
return json_string;
}
public class Testing extends TimerTask {
public void run() {
Toast.makeText(recuperationJson.this, "test", Toast.LENGTH_SHORT).show();
}
}
我的日誌
E/AndroidRuntime: FATAL EXCEPTION: Timer-0
Process: com.suprem.projetfinal, PID: 3196
java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
at android.os.Handler.<init>(Handler.java:200)
at android.os.Handler.<init>(Handler.java:114)
at android.widget.Toast$TN.<init>(Toast.java:344)
at android.widget.Toast.<init>(Toast.java:100)
at android.widget.Toast.makeText(Toast.java:258)
at com.suprem.projetfinal.recuperationJson$Testing$override.run(recuperationJson.java:48)
at com.suprem.projetfinal.recuperationJson$Testing$override.access$dispatch(recuperationJson.java)
at com.suprem.projetfinal.recuperationJson$Testing.run(recuperationJson.java:0)
at java.util.Timer$TimerImpl.run(Timer.java:284)
你只是想分析或得到其持續12分鐘大數據?或者在12分鐘後運行代碼? – mismanc