onCreate()
내 활동의 경우 을 예약 할 Timer
+ TimerTask
입니다. mainThread
에있는 ParseQuerry
콜백에서 간단한 UI 업데이트를 만들기 위해 인터페이스 콜백을 위임합니다. 이것은 활동을 변경하지 않을 때 작동합니다. 하지만 활동을 종료하고 다시 입력하면 (특정 시점의 활동을 시작할 때만 생성되므로 새 타이머는 여기에 생성되지 않습니다) 작동하지 않습니다. Activity 인스턴스가있는 것 같지만 처리 할 수 없습니다. 성공하지,활동 다시 시작 후 타이머에서 활동 UI 업데이트
public class Utils{
.......
doParseQuery(Context ctx, MyListener listener){
.......
query.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if(e == null){
....
listener.onSuccess();
}
}
});
}
}
내가 시도 무엇 :
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
....
uiTimer = new Timer();
uiTask = new TimerTask() {
@Override
public void run() {
doParseTask();
}
};
uiTimer.schedule(uiTask, shortCodeLeft);
}
doParseTask(){
Utils.doParseQuery(this, new MyListener{
@Override
public void onSuccess() {
updateUI();
}
});
}
updateUI(){
Log.i(TAG, "Show changed layout"); //This is always shown, this way I ensure it gets here!!
mTextView.setText(foo); //this doesn't work
mLayout.setVisibility(View.GONE); //this doesn't work
}
ParseQuery
이 done()
콜백 메소드에서 실행되고, 나는 UI를 업데이트하는 함수를 호출
1. make the `uiTimer` and `uiTask` static global variables; // I thought that maybe it gets leaked into activity instances
2. update the UI using
runOnUiThread(new Runnable() {
@Override
public void run() {}
});
OR
mLayout.post(new Runnable() {
@Override
public void run() {
mLayout.setVisibility(View.GONE);
}
});
3. android:launchMode= "singleInstance" //in Manifest