2011-03-14 3 views
-1

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); 
     } 

    }; 




} 
+0

문제가 무엇 OnCreate()에서 dialog = new ProgressDialog(this); 를 인스턴스화 할 수 있습니까? – Nanis

+0

나는이 코드를 작성했으나 NT 작업 중 ...... 애플리케이션이 발생하면 강제로 닫히지 않았다. 대화 또는 쓰기인지 여부를 알려주는 ??? – Smith

답변

0
@Override 
public IBinder onBind(Intent intent) { 
    return null; 
} 

@Override 
public void onCreate() { 

Intent i = new Intent(getBaseContext(), CustomDialogExample.class); 
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
getApplication().startActivity(i); 



} 

이를 시도하고 괜찮아요 경우에 저 말) 코드에서

+0

안녕하세요 .its NT 작업 선생님 ..... 내가 당신에게 전체 사용 사례를 제공 할 수 있는지 여부를 그래서 당신은 정확히 어떤 문제인지 알고있어 ... !!! – Smith

+0

예, 더 많은 코드를 넣을 수 있다면 더 쉽습니다. 특히 스택 추적을하십시오. – Nanis

+0

@nanis 안녕하세요, 실제로 내가 포함하는 응용 프로그램을 만들었습니다 : - 두 개의 텍스트 상자와 하나의 단추가있는 하나의 레이아웃. 단추를 누른 후 대화 상자에서 진행률 막대가 시작되었습니다. 그리고 다음 활동을 호출했습니다. (메시지 대화 상자) 진행률 표시 줄이 최대 값 대화 메시지에 도달했을 때 표시됩니다 ..하지만 백그라운드에서 실행하고 다른 응용 프로그램과 함께 놀고 싶을 때 내 메시지 대화 상자는 현재 응용 프로그램에 표시되어야합니다 ..... .right 지금 대화 메시지가 내 응용 프로그램에서만 팝업으로 표시됩니다. 그것을 달성하기 위해 도와주세요 ..... --Thanks 사전에 .... \t 처리기 progressHandler = 새로운 핸들러()를 업데이트하는 배경에 대한 – Smith

0
dialog = new ProgressDialog(this); 

this이없는 활동을 OnClickListener를하는 의미

dialog = new ProgressDialog(arg0) 

또는 dialog = new ProgressDialog(oddg.this)

시도,

하거나

관련 문제