在我的应用程序中,我正在使用Dropbox库,当我第一次点击dropbox文件下载时,它会开始下载文件并将该文件保存到我的SD卡中...
但是当我第二次点击Dropbox文件下载按钮时,首先验证后再进行身份验证,它显示以下错误???????
03-28 16:17:32.610:E / WindowManager(20903):活动 xyz.dropboxActivity泄露了窗口 com.android.internal.policy.impl.PhoneWindow$DecorView@2f474670那个 最初添加到这里03-28 16:17:32.610:E / WindowManager(20903): android.view.WindowLeaked:活动xyz.dropboxActivity已泄露 window com.android.internal.policy.impl.PhoneWindow$DecorView@2f474670 最初添加的内容03-28 16:17:32.660: E / AndroidRuntime(20903):android.view.WindowManager $ BadTokenException: 无法添加窗口 - 令牌android.os.BinderProxy@2f4d63e0不是 有效;你的活动在运行吗?
有人可以告诉我为什么???
[编辑]
final static private String APP_KEY = "";
final static private String APP_SECRET = "";
private static final String TAG = "Dropbox";
final static private AccessType ACCESS_TYPE = AccessType.DROPBOX;
final static private String ACCOUNT_PREFS_NAME = "prefs";
final static private String ACCESS_KEY_NAME = "ACCESS_KEY";
final static private String ACCESS_SECRET_NAME = "ACCESS_SECRET";
DropboxAPI<AndroidAuthSession> mApi;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidAuthSession session = buildSession();
mApi = new DropboxAPI<AndroidAuthSession>(session);
checkAppKeySetup();
// Start the remote authentication
mApi.getSession().startAuthentication(dropboxActivity.this);
Log.i("mApi.getSessionm", ""+mApi.getSession());
}
protected void onResume() {
super.onResume();
AndroidAuthSession session = mApi.getSession();
// The next part must be inserted in the onResume() method of the
// activity from which session.startAuthentication() was called, so
// that Dropbox authentication completes properly.
if (session.authenticationSuccessful()) {
try {
// Mandatory call to complete the auth
session.finishAuthentication();
Log.i("4", "4");
/*Intent i=getIntent();
Bundle b=i.getExtras();
String FileName=b.getString("Filename");*/
String FileName="sample_1.csv";
Log.i("FileName",FileName);
download download_obj=new download(dropboxActivity.this, mApi,FileName); //The error comes at this line when I am calling download with this context
download_obj.execute();
} catch (IllegalStateException e) {
showToast("Couldn't authenticate with Dropbox:" + e.getLocalizedMessage());
Log.i(TAG, "Error authenticating", e);
}
A * 和download.java文件是: *
public class download extends AsyncTask<Void,Integer,Boolean>{
private Activity context;
ProgressDialog dialog=null;
DropboxAPI<AndroidAuthSession> mApi;
String FileName;
download(Activity context,DropboxAPI<AndroidAuthSession> mApi,String FileName)
{
this.context=context;
this.mApi=mApi;
this.FileName=FileName;
}
@Override
protected void onPreExecute()
{
dialog=new ProgressDialog(context);
dialog.setMessage("Loading...");
dialog.show();
}
@Override
protected Boolean doInBackground(Void... arg0) {
// TODO Auto-generated method stub
File file= new File("/sdcard/"+FileName);
OutputStream out= null;
boolean result=false;
try {
out = new BufferedOutputStream(new FileOutputStream(file));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
DropboxFileInfo info = mApi.getFile("aaa"+FileName, null, out, null);
Log.i("DbExampleLog", "The file's rev is: " + info.getMetadata().rev);
Intent JumpToParseCSV=new Intent(context,ParseCSV.class);
JumpToParseCSV.putExtra("FileName", file.getAbsolutePath());
Log.i("path", "FileName"+ file.getAbsolutePath());
((Activity) context).finish();
context.startActivity(JumpToParseCSV);
result=true;
} catch (DropboxException e) {
Log.e("DbExampleLog", "Something went wrong while downloading.");
file.delete();
result=false;
}
return result;
}
@Override
protected void onProgressUpdate(Integer... values)
{
super.onProgressUpdate(values);
// dialog.incrementProgressBy(5);
}
@Override
protected void onPostExecute(Boolean result)
{
dialog.dismiss();
if(result==true)
{
new AlertDialog.Builder(context)
.setTitle("Info")
.setMessage("Selected file has been uploaded, Please navigate to DashBoard!!")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
else
{
new AlertDialog.Builder(context)
.setTitle("Info")
.setMessage("Something went wrong while downloading!!")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent i=new Intent(context,jjj.class);
((Activity) context).finish();
context.startActivity(i);
}
}).show();
}
//Log.i("database", "completed database");
}
}
[编辑]
Activity xyz.dropboxActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405f4d20 that was originally added here
android.view.WindowLeaked: Activity com.kxs.allen.dropboxActivity has leaked window
com.android.internal.policy.impl.PhoneWindow$DecorView@405f4d20 that was originally added here
at android.view.ViewRoot.<init>(ViewRoot.java:259)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
at android.view.Window$LocalWindowManager.addView(Window.java:424)
at android.app.Dialog.show(Dialog.java:241)
at com.kxs.allen.download.onPreExecute(download.java:39)
at android.os.AsyncTask.execute(AsyncTask.java:391)
at com.kxs.allen.dropboxActivity.onResume(dropboxActivity.java:139)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
at android.app.Activity.performResume(Activity.java:3832)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2114)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3733)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:893)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:651)
at dalvik.system.NativeStart.main(Native Method)
threadid=1: thread exiting with uncaught exception (group=0x40018560)
FATAL EXCEPTION: main java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
at android.view.Window$LocalWindowManager.removeView(Window.java:432)
at android.app.Dialog.dismissDialog(Dialog.java:278)
at android.app.Dialog.access$000(Dialog.java:71)
at android.app.Dialog$1.run(Dialog.java:111)
at android.app.Dialog.dismiss(Dialog.java:268)
at com.kxs.allen.download.onPostExecute(download.java:81)
at com.kxs.allen.download.onPostExecute(download.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3733)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:893)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:651)
at dalvik.system.NativeStart.main(Native Method)
03-28 17:47:37.199: E/AndroidRuntime(2489): [Blue Error Handler] Make Debugging Report file for main
03-28 17:47:37.199: E/AndroidRuntime(2489): **java.lang.IllegalArgumentException: View not attached to window manager**
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
at android.view.Window$LocalWindowManager.removeView(Window.java:432)
at android.app.Dialog.dismissDialog(Dialog.java:278)
at android.app.Dialog.access$000(Dialog.java:71)
at android.app.Dialog$1.run(Dialog.java:111)
at android.app.Dialog.dismiss(Dialog.java:268)
at com.kxs.allen.download.onPostExecute(download.java:81)
at com.kxs.allen.download.onPostExecute(download.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3733)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:893)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:651)
at dalvik.system.NativeStart.main(Native Method)
请给我一些建议???
答案 0 :(得分:0)
我想在下面提出建议。根据你的代码看起来像上下文导致问题。
建议1: 尝试使用当前活动,例如“xxxxActivity.this”
dialog=new ProgressDialog(context);
dialog=new ProgressDialog(xxxxActivity.this);
建议2:
if(!isFinishing())
{
dialog=new ProgressDialog(xxxxActivity.this);
....
....
dialog.show();
}