긴 계산이 제대로 작동하지 않습니다,하지만 난 여전히 100 %를 못 했어. 나는 근본적으로 최종 목표에 가깝게 똑같이 두 개의 분리 된 막 다른 골목에 왔습니다.해서 ProgressDialog 내가이해서 ProgressDialog가 제대로 작동하도록하기 위해 많은 것들을 시도
첫째, 여분의 Thread
를 생성하고 runOnUiThread
를 사용했습니다. 이것은 내가 그것을 할 적절한 시간에 대화 showing
및 dismissing
결과지만, 스피너는 회전하지 않습니다. 고정되어 있으며 결코 조정되지 않습니다.
readButton = (Button) findViewById(R.id.readButton);
readButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
final ProgressDialog pd = new ProgressDialog(Waves.this);
pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pd.setMessage("Reading...");
pd.setCancelable(false);
pd.show();
Thread export = new Thread() {
public void run() {
if(myService.getState() != 3) {
runOnUiThread(new Runnable() {
public void run() {
Log.i("myService", "12222");
myService.setHandler(mHandler);
myService.connect(MainMenu.previousDevice, true);
}
});
} else {
runOnUiThread(new Runnable() {
public void run() {
readWaves();
}
});
}
mHandler.obtainMessage(MainMenu.READ_FINISHED).sendToTarget();
pd.dismiss();
}
};
export.start();
}
});
내가하고 시도 다음 일은
는AsyncTask
를 사용합니다. 내가 인터넷에서 찾은 것에서부터 이것은 갈 길과 같습니다. 회 전자가 회전을 시작하고 코드가 작동하기 시작하지만 짧은 시간이 지나면 응용 프로그램이 현재 활동을 떠나 완전히 다시 시작됩니다. 아래에
LogCat
이 나와 있지만 오류는 표시되지 않습니다.
readButton = (Button) findViewById(R.id.readButton);
readButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
new readPage().execute(null, null, null);
}
});
public class readPage extends AsyncTask<Void, Void, Void> {
private ProgressDialog pdia;
@Override
protected void onPreExecute(){
super.onPreExecute();
pdia = new ProgressDialog(Waves.this);
pdia.setMessage("Reading...");
pdia.setCancelable(false);
pdia.show();
}
@Override
protected void onPostExecute(Void unused) {
pdia.dismiss();
}
@Override
protected Void doInBackground(Void... arg0) {
// TODO Auto-generated method stub
Log.i("ASYNC", "2");
if(myService.getState() != 3) {
myService.setHandler(mHandler);
myService.connect(MainMenu.previousDevice, true);
} else {
readWaves();
}
return null;
}
}
여기는 LogCat
입니다. 표시된 첫 번째 줄은 내 코드의 일부인 LogCat
의 마지막 것입니다. 이 코드는 항상 작동하기 때문에이 줄에서 어떤 일이 발생하는지 확인하지 않았습니다.이 코드는 AsyncTask
으로 구현되지 않았습니다. 마지막 줄에는 응용 프로그램이 다시 시작될 때 Main Menu ++ ON CREATE ++
항목이 있습니다.
01-07 18:23:27.738: W/NATIVE CODE(28111): After SetBaud
01-07 18:23:29.777: I/dalvikvm(28111): threadid=4: reacting to signal 3
01-07 18:23:30.781: W/dalvikvm(28111): threadid=4: spin on suspend #1 threadid=9 (pcf=0)
01-07 18:23:30.781: D/dalvikvm(28111): Temporarily moving tid 28128 to fg (was 0)
01-07 18:23:30.781: D/dalvikvm(28111): Temporarily raised priority on tid 28128 (10 -> 0)
01-07 18:23:31.527: W/dalvikvm(28111): threadid=4: spin on suspend #2 threadid=9 (pcf=3)
01-07 18:23:31.531: I/dalvikvm(28111): "Signal Catcher" daemon prio=5 tid=4 RUNNABLE
01-07 18:23:31.531: I/dalvikvm(28111): | group="system" sCount=0 dsCount=0 obj=0x4050f730 self=0x117d60
01-07 18:23:31.531: I/dalvikvm(28111): | sysTid=28114 nice=0 sched=0/0 cgrp=default handle=582800
01-07 18:23:31.531: I/dalvikvm(28111): at dalvik.system.NativeStart.run(Native Method)
01-07 18:23:31.531: I/dalvikvm(28111): "AsyncTask #1" prio=5 tid=9 RUNNABLE
01-07 18:23:31.531: I/dalvikvm(28111): | group="main" sCount=1 dsCount=0 obj=0x40559388 self=0x2e1a10
01-07 18:23:31.531: I/dalvikvm(28111): | sysTid=28128 nice=0 sched=0/0 cgrp=default handle=3243272
01-07 18:23:31.925: I/dalvikvm(28111): at my.eti.commander.RelayAPIModel$NativeCalls.GetWavesJava(Native Method)
01-07 18:23:31.933: I/dalvikvm(28111): at my.eti.commander.Waves.readWaves(Waves.java:365)
01-07 18:23:31.937: I/dalvikvm(28111): at my.eti.commander.Waves.access$0(Waves.java:350)
01-07 18:23:31.941: I/dalvikvm(28111): at my.eti.commander.Waves$readPage.doInBackground(Waves.java:323)
01-07 18:23:31.945: I/dalvikvm(28111): at my.eti.commander.Waves$readPage.doInBackground(Waves.java:1)
01-07 18:23:31.949: I/dalvikvm(28111): at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-07 18:23:31.957: I/dalvikvm(28111): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
01-07 18:23:31.960: I/dalvikvm(28111): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-07 18:23:31.964: I/dalvikvm(28111): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
01-07 18:23:31.968: I/dalvikvm(28111): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
01-07 18:23:31.972: I/dalvikvm(28111): at java.lang.Thread.run(Thread.java:1019)
01-07 18:23:32.734: W/dalvikvm(28111): threadid=4: spin on suspend #3 threadid=9 (pcf=3)
01-07 18:23:32.734: I/dalvikvm(28111): "Signal Catcher" daemon prio=5 tid=4 RUNNABLE
01-07 18:23:32.734: I/dalvikvm(28111): | group="system" sCount=0 dsCount=0 obj=0x4050f730 self=0x117d60
01-07 18:23:32.734: I/dalvikvm(28111): | sysTid=28114 nice=0 sched=0/0 cgrp=default handle=582800
01-07 18:23:32.734: I/dalvikvm(28111): at dalvik.system.NativeStart.run(Native Method)
01-07 18:23:32.734: I/dalvikvm(28111): "AsyncTask #1" prio=5 tid=9 RUNNABLE
01-07 18:23:32.734: I/dalvikvm(28111): | group="main" sCount=1 dsCount=0 obj=0x40559388 self=0x2e1a10
01-07 18:23:32.734: I/dalvikvm(28111): | sysTid=28128 nice=0 sched=0/0 cgrp=default handle=3243272
01-07 18:23:32.859: I/dalvikvm(28111): at my.eti.commander.RelayAPIModel$NativeCalls.GetWavesJava(Native Method)
01-07 18:23:32.859: I/dalvikvm(28111): at my.eti.commander.Waves.readWaves(Waves.java:365)
01-07 18:23:32.859: I/dalvikvm(28111): at my.eti.commander.Waves.access$0(Waves.java:350)
01-07 18:23:32.859: I/dalvikvm(28111): at my.eti.commander.Waves$readPage.doInBackground(Waves.java:323)
01-07 18:23:32.859: I/dalvikvm(28111): at my.eti.commander.Waves$readPage.doInBackground(Waves.java:1)
01-07 18:23:32.859: I/dalvikvm(28111): at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-07 18:23:32.859: I/dalvikvm(28111): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
01-07 18:23:32.859: I/dalvikvm(28111): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-07 18:23:32.859: I/dalvikvm(28111): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
01-07 18:23:32.859: I/dalvikvm(28111): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
01-07 18:23:32.863: I/dalvikvm(28111): at java.lang.Thread.run(Thread.java:1019)
01-07 18:23:33.613: W/dalvikvm(28111): threadid=4: spin on suspend #4 threadid=9 (pcf=3)
01-07 18:23:33.613: I/dalvikvm(28111): "Signal Catcher" daemon prio=5 tid=4 RUNNABLE
01-07 18:23:33.613: I/dalvikvm(28111): | group="system" sCount=0 dsCount=0 obj=0x4050f730 self=0x117d60
01-07 18:23:33.613: I/dalvikvm(28111): | sysTid=28114 nice=0 sched=0/0 cgrp=default handle=582800
01-07 18:23:33.613: I/dalvikvm(28111): at dalvik.system.NativeStart.run(Native Method)
01-07 18:23:33.613: I/dalvikvm(28111): "AsyncTask #1" prio=5 tid=9 RUNNABLE
01-07 18:23:33.617: I/dalvikvm(28111): | group="main" sCount=1 dsCount=0 obj=0x40559388 self=0x2e1a10
01-07 18:23:33.617: I/dalvikvm(28111): | sysTid=28128 nice=0 sched=0/0 cgrp=default handle=3243272
01-07 18:23:33.617: I/dalvikvm(28111): at my.eti.commander.RelayAPIModel$NativeCalls.GetWavesJava(Native Method)
01-07 18:23:33.617: I/dalvikvm(28111): at my.eti.commander.Waves.readWaves(Waves.java:365)
01-07 18:23:33.617: I/dalvikvm(28111): at my.eti.commander.Waves.access$0(Waves.java:350)
01-07 18:23:33.617: I/dalvikvm(28111): at my.eti.commander.Waves$readPage.doInBackground(Waves.java:323)
01-07 18:23:33.617: I/dalvikvm(28111): at my.eti.commander.Waves$readPage.doInBackground(Waves.java:1)
01-07 18:23:33.617: I/dalvikvm(28111): at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-07 18:23:33.617: I/dalvikvm(28111): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
01-07 18:23:33.617: I/dalvikvm(28111): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-07 18:23:33.617: I/dalvikvm(28111): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
01-07 18:23:33.617: I/dalvikvm(28111): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
01-07 18:23:33.617: I/dalvikvm(28111): at java.lang.Thread.run(Thread.java:1019)
01-07 18:23:34.367: W/dalvikvm(28111): threadid=4: spin on suspend #5 threadid=9 (pcf=3)
01-07 18:23:34.367: I/dalvikvm(28111): "Signal Catcher" daemon prio=5 tid=4 RUNNABLE
01-07 18:23:34.367: I/dalvikvm(28111): | group="system" sCount=0 dsCount=0 obj=0x4050f730 self=0x117d60
01-07 18:23:34.367: I/dalvikvm(28111): | sysTid=28114 nice=0 sched=0/0 cgrp=default handle=582800
01-07 18:23:34.371: I/dalvikvm(28111): at dalvik.system.NativeStart.run(Native Method)
01-07 18:23:34.371: I/dalvikvm(28111): "AsyncTask #1" prio=5 tid=9 RUNNABLE
01-07 18:23:34.371: I/dalvikvm(28111): | group="main" sCount=1 dsCount=0 obj=0x40559388 self=0x2e1a10
01-07 18:23:34.371: I/dalvikvm(28111): | sysTid=28128 nice=0 sched=0/0 cgrp=default handle=3243272
01-07 18:23:34.371: I/dalvikvm(28111): at my.eti.commander.RelayAPIModel$NativeCalls.GetWavesJava(Native Method)
01-07 18:23:34.371: I/dalvikvm(28111): at my.eti.commander.Waves.readWaves(Waves.java:365)
01-07 18:23:34.371: I/dalvikvm(28111): at my.eti.commander.Waves.access$0(Waves.java:350)
01-07 18:23:34.371: I/dalvikvm(28111): at my.eti.commander.Waves$readPage.doInBackground(Waves.java:323)
01-07 18:23:34.371: I/dalvikvm(28111): at my.eti.commander.Waves$readPage.doInBackground(Waves.java:1)
01-07 18:23:34.371: I/dalvikvm(28111): at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-07 18:23:34.371: I/dalvikvm(28111): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
01-07 18:23:34.371: I/dalvikvm(28111): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-07 18:23:34.371: I/dalvikvm(28111): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
01-07 18:23:34.371: I/dalvikvm(28111): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
01-07 18:23:34.371: I/dalvikvm(28111): at java.lang.Thread.run(Thread.java:1019)
01-07 18:23:35.253: E/MainMenu(28151): +++ ON CREATE +++
편집 :
나는 또한 내가 .hide()
대신 .dismiss()
의 사용 시도 추가 할,하지만 난 그게 문제라고 생각하지 않습니다. 사용 될 때마다 ProgressDialog
의 새 인스턴스를 만듭니다.
정확히 readWaves() 메소드에서 무엇을하고 있습니까? 문제가있는 것처럼 응용 프로그램이 있기 때문에 스레드 문제로 충돌하고 나는 전체를 많이하고 있어요 잘하지 않는해서 ProgressDialog –
에 직접 관련이 있음을 나에게 보인다. NDK와 JNI를 사용하여 응용 프로그램과 기존 C 라이브러리를 앞뒤로 호출합니다. 기본적으로, 나는 내 C 라이브러리에서 함수를 호출하는 readWaves()를 호출한다. C 라이브러리는 자바 측의 블루투스 스트림을 사용하여 많은 비트를 보내고받습니다. 수신 된 비트에 따라 C 라이브러리의 변수가 다른 값으로 설정됩니다. 그런 다음 readWaves() 후에 C 라이브러리에서 업데이트 된 값을 확인하여 UI를 업데이트합니다. – JuiCe