进度对话框有什么问题? java文件:
public class Start_Screen extends Menu_Activity {
List<Bitmap> lbmp;
List<String> ltitles;
List<String> ldesc;
Custom_Adapter adapter;
ProgressDialog pd;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.start_screen);
pd = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER);
pd.setTitle("Downloading...");
pd.setMessage("Please wait.");
pd.setCancelable(false);
ListView list = (ListView) findViewById(R.id.soundslist);
lbmp = new ArrayList<Bitmap>();
ltitles = new ArrayList<String>();
ldesc = new ArrayList<String>();
new Download().execute();
adapter = new Custom_Adapter(this, lbmp, ltitles);
list.setAdapter(adapter);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
public class Download extends AsyncTask<Void, Void, Void>{
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
pd.dismiss();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
String url = "picsite.comze.com/?json=1";
F JSONparser = new F();
JSONObject picsite = JSONparser.getJSONFromUrl(url);
try {
JSONArray posts = picsite.getJSONArray("posts");
for(int i=0;i<posts.length();i++){
JSONObject post = posts.getJSONObject(i);
String title = post.getString("title");
ltitles.add(title);
JSONArray photos = post.getJSONArray("attachments");
JSONObject photo = photos.getJSONObject(0);
String URL = photo.getString("url");
URL downURL = new URL(URL);
HttpURLConnection connect = (HttpURLConnection)downURL.openConnection();
connect.setDoOutput(true);
connect.connect();
InputStream is = connect.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
lbmp.add(bmp);
String desc = photo.getString("description");
ldesc.add(desc);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pd.show();
}
}
}
这是logcat:
09-22 06:39:24.835: E/WindowManager(1319): Activity com.tendarius.sounds.Start_Screen has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{411a6c08 V.E..... R.....ID 0,0-480,243} that was originally added here
09-22 06:39:24.835: E/WindowManager(1319): android.view.WindowLeaked: Activity com.tendarius.sounds.Start_Screen has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{411a6c08 V.E..... R.....ID 0,0-480,243} that was originally added here
09-22 06:39:24.835: E/WindowManager(1319): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
09-22 06:39:24.835: E/WindowManager(1319): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
09-22 06:39:24.835: E/WindowManager(1319): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
09-22 06:39:24.835: E/WindowManager(1319): at android.app.Dialog.show(Dialog.java:281)
09-22 06:39:24.835: E/WindowManager(1319): at com.tendarius.sounds.Start_Screen$Download.onPreExecute(Start_Screen.java:126)
09-22 06:39:24.835: E/WindowManager(1319): at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586)
09-22 06:39:24.835: E/WindowManager(1319): at android.os.AsyncTask.execute(AsyncTask.java:534)
09-22 06:39:24.835: E/WindowManager(1319): at com.tendarius.sounds.Start_Screen.onCreate(Start_Screen.java:49)
09-22 06:39:24.835: E/WindowManager(1319): at android.app.Activity.performCreate(Activity.java:5104)
09-22 06:39:24.835: E/WindowManager(1319): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
09-22 06:39:24.835: E/WindowManager(1319): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
09-22 06:39:24.835: E/WindowManager(1319): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
09-22 06:39:24.835: E/WindowManager(1319): at android.app.ActivityThread.access$600(ActivityThread.java:141)
09-22 06:39:24.835: E/WindowManager(1319): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
09-22 06:39:24.835: E/WindowManager(1319): at android.os.Handler.dispatchMessage(Handler.java:99)
09-22 06:39:24.835: E/WindowManager(1319): at android.os.Looper.loop(Looper.java:137)
09-22 06:39:24.835: E/WindowManager(1319): at android.app.ActivityThread.main(ActivityThread.java:5041)
09-22 06:39:24.835: E/WindowManager(1319): at java.lang.reflect.Method.invokeNative(Native Method)
09-22 06:39:24.835: E/WindowManager(1319): at java.lang.reflect.Method.invoke(Method.java:511)
09-22 06:39:24.835: E/WindowManager(1319): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-22 06:39:24.835: E/WindowManager(1319): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
09-22 06:39:24.835: E/WindowManager(1319): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
您应该在显示之前创建对话框。
例如:
pd.create()表示(); 代替
pd.show();
同样在你的onPostExecute中检查pd!= null然后执行pd.dismiss();
答案 1 :(得分:0)
通过检查asynctask
中的isfinishing()来检查活动是否存在 if(!(Activity) context).isFinishing()){
dialog.show();
}
if(!(Activity) context).isFinishing()){
dialog.cancel();
}