package safeluck.drive.evaluation.viewmodels;
|
|
|
import android.arch.lifecycle.LiveData;
|
import android.arch.lifecycle.MutableLiveData;
|
import android.arch.lifecycle.ViewModel;
|
import android.util.Log;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import com.anyun.exam.lib.MyLog;
|
|
public class MainViewModel extends ViewModel {
|
private static final String TAG = "MainViewModel";
|
AtomicInteger atomicInteger = new AtomicInteger(0);
|
private MutableLiveData<String> json = new MutableLiveData<>();
|
public LiveData<String> getJson(){
|
//往json字符串写入数据
|
loadJson();
|
return json;
|
}
|
|
private void loadJson() {
|
MyLog.i("loadJson");
|
new Thread(new Runnable() {
|
@Override
|
public void run() {
|
try {
|
Thread.sleep(10*1000);
|
} catch (InterruptedException e) {
|
e.printStackTrace();
|
}
|
|
Log.i(TAG, "run: "+ atomicInteger.incrementAndGet());
|
json.postValue("我爱你JetPack!!"+atomicInteger.get());
|
}
|
}).start();
|
}
|
|
}
|