Page 723 - 3-2
P. 723
import android.widget.TextView;
import java.util.Timer;
import java.util.TimerTask;
public class Information_Activity extends AppCompatActivity {
TextView num;
TextView money;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_information_);
final Intent Service = new Intent(Information_Activity.this, MyService.class);
startService(Service);
num = (TextView)findViewById(R.id.num_text);
money = (TextView)findViewById(R.id.money_text);
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
public void run() {
Information_Activity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
num.setText(MyService.num);
money.setText(MyService.money);
}
});
}
};
timer.schedule(timerTask, 0, 10); //0 초 이후 시작하여 1s 마다 한번씩 timeTask 의 run 을 작
동시킨다.
}
}
-------------------------------------------------------------
E. MyService
package kr.icehs.intec.management;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
- 723 -