public class oddg extends Activity 액티비티 구현 OnClickListener { ProgressDialog 대화 상자; int increment; int 최대; private static final String TAG = "ServicesDemo";서비스에서 호출 된 액티비티
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
Button startbtn = (Button) findViewById(R.id.startbtn);
startbtn.setOnClickListener(this);
}
// // @Override 공개 onKeyDown에 부울 (INT 키 코드, 이벤트의 KeyEvent) {// 경우 (keyCode에 == KeyEvent.KEYCODE_BACK & & event.getRepeatCount() == 0) { //
// moveTaskToBack (true); //} // super.onKeyDown (keyCode, event)를 반환합니다. //}
@Override
public void onClick(View arg0)
{
// get the increment value from the text box
EditText et = (EditText) findViewById(R.id.increment);
// convert the text value to a integer
increment = Integer.parseInt(et.getText().toString());
dialog = new ProgressDialog(this);
dialog.setCancelable(true);
dialog.setMessage("Loading...");
// set the progress to be horizontal
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
// reset the bar to the default value of 0
dialog.setProgress(0);
// get the maximum value
EditText max = (EditText) findViewById(R.id.maximum);
// convert the text value to a integer
maximum = Integer.parseInt(max.getText().toString());
// set the maximum value
dialog.setMax(maximum);
// display the progressbar
dialog.show();
// create a thread for updating the progress bar
Thread background = new Thread (new Runnable() {
public void run()
{
try
{
// enter the code to be run while displaying the progressbar.
//
// This example is just going to increment the progress bar:
// So keep running until the progress value reaches maximum value
while(dialog.getProgress()<= dialog.getMax())
{
// wait 500ms between each update
Thread.sleep(500);
// active the update handler
progressHandler.sendMessage(progressHandler.obtainMessage());
}
}
catch (java.lang.InterruptedException e)
{
// if something fails do something smart
}
}
});
// start the background thread
background.start();
//oddg o1 = new oddg();
// o1.onPause();
}
// handler for the background updating
Handler progressHandler = new Handler()
{
public void handleMessage(Message msg)
{
if(dialog.getProgress()== dialog.getMax())
{
// Log.d (TAG, "온 클릭 : srvice 중지"); //
// stopService (새 인 텐트 (oddg.this, MyService.class));
Log.d(TAG, "onClick: starting service");
startService(new Intent(oddg.this, MyService.class));
}
dialog.incrementProgressBy(increment);
}
};
}
문제가 무엇
OnCreate()
에서dialog = new ProgressDialog(this);
를 인스턴스화 할 수 있습니까? – Nanis나는이 코드를 작성했으나 NT 작업 중 ...... 애플리케이션이 발생하면 강제로 닫히지 않았다. 대화 또는 쓰기인지 여부를 알려주는 ??? – Smith