java点击按钮凹陷_java-单击对话框按钮时泄漏的窗口

当我的墙纸应用程序用户单击“关于”按钮时,我试图向他们显示一个“关于”页面,但是我在日志猫中看到泄漏的窗口错误,并且活动在显示对话框之前退出.

这是代码:

/*

*

* Sensational Wallpapers Pack 1

*

* Wallpaper Designed by AZ2ENVY

*

*/

package com.death2all110.SensationalWallpapers1;

import android.app.Activity;

import android.content.res.Resources;

import android.graphics.BitmapFactory;

import android.graphics.Bitmap;

import android.graphics.drawable.Drawable;

import android.os.Bundle;

import android.os.AsyncTask;

import android.util.Log;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.view.Window;

import android.view.View.OnClickListener;

import android.widget.AdapterView;

import android.widget.BaseAdapter;

import android.widget.Gallery;

import android.widget.ImageView;

import android.widget.Toast;

import android.app.AlertDialog;

import android.widget.Button;

import android.content.DialogInterface;

import java.io.IOException;

import java.io.InputStream;

import java.util.ArrayList;

import com.death2all110.SensationalWallpapers1.R;

public class wallpaper extends Activity implements AdapterView.OnItemSelectedListener,

OnClickListener {

private Gallery mGallery;

private ImageView mImageView;

private boolean mIsWallpaperSet;

private Bitmap mBitmap;

private ArrayList mThumbs;

private ArrayList mImages;

private WallpaperLoader mLoader;

@Override

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

requestWindowFeature(Window.FEATURE_NO_TITLE);

findWallpapers();

setContentView(R.layout.wallpaper_chooser);

mGallery = (Gallery) findViewById(R.id.gallery);

mGallery.setAdapter(new ImageAdapter(this));

mGallery.setOnItemSelectedListener(this);

mGallery.setCallbackDuringFling(false);

findViewById(R.id.set).setOnClickListener(this);

mImageView = (ImageView) findViewById(R.id.wallpaper);

Button alert = (Button) findViewById(R.id.about_page);

alert.setOnClickListener(this);

}

private void findWallpapers() {

mThumbs = new ArrayList(24);

mImages = new ArrayList(24);

final Resources resources = getResources();

final String packageName = getApplication().getPackageName();

addWallpapers(resources, packageName, R.array.wallpapers);

addWallpapers(resources, packageName, R.array.extra_wallpapers);

}

private void addWallpapers(Resources resources, String packageName, int list) {

final String[] extras = resources.getStringArray(list);

for (String extra : extras) {

int res = resources.getIdentifier(extra, "drawable", packageName);

if (res != 0) {

final int thumbRes = resources.getIdentifier(extra + "_small",

"drawable", packageName);

if (thumbRes != 0) {

mThumbs.add(thumbRes);

mImages.add(res);

}

}

}

}

@Override

protected void onResume() {

super.onResume();

mIsWallpaperSet = false;

}

@Override

protected void onDestroy() {

super.onDestroy();

if (mLoader != null && mLoader.getStatus() != WallpaperLoader.Status.FINISHED) {

mLoader.cancel(true);

mLoader = null;

}

}

public void onItemSelected(AdapterView parent, View v, int position, long id) {

if (mLoader != null && mLoader.getStatus() != WallpaperLoader.Status.FINISHED) {

mLoader.cancel();

}

mLoader = (WallpaperLoader) new WallpaperLoader().execute(position);

}

/*

* When using touch if you tap an image it triggers both the onItemClick and

* the onTouchEvent causing the wallpaper to be set twice. Ensure we only

* set the wallpaper once.

*/

private void selectWallpaper(int position) {

if (mIsWallpaperSet) {

return;

}

mIsWallpaperSet = true;

try {

InputStream stream = getResources().openRawResource(mImages.get(position));

setWallpaper(stream);

setResult(RESULT_OK);

finish();

} catch (IOException e) {

Log.e("Paperless System", "Failed to set wallpaper: " + e);

}

}

public void onNothingSelected(AdapterView parent) {

}

private class ImageAdapter extends BaseAdapter {

private LayoutInflater mLayoutInflater;

ImageAdapter(wallpaper context) {

mLayoutInflater = context.getLayoutInflater();

}

public int getCount() {

return mThumbs.size();

}

public Object getItem(int position) {

return position;

}

public long getItemId(int position) {

return position;

}

public View getView(int position, View convertView, ViewGroup parent) {

ImageView image;

if (convertView == null) {

image = (ImageView) mLayoutInflater.inflate(R.layout.wallpaper_item, parent, false);

} else {

image = (ImageView) convertView;

}

int thumbRes = mThumbs.get(position);

image.setImageResource(thumbRes);

Drawable thumbDrawable = image.getDrawable();

if (thumbDrawable != null) {

thumbDrawable.setDither(true);

} else {

Log.e("Paperless System", String.format(

"Error decoding thumbnail resId=%d for wallpaper #%d",

thumbRes, position));

}

return image;

}

}

public void onClick(View v) {

selectWallpaper(mGallery.getSelectedItemPosition());

}

public void onClick1(View about) {

// If "About was clicked.....

if (about == findViewById(R.id.about_page)) {

// Prepare the alert box!!

AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

// Set message to display...

alertbox.setMessage("Test.....");

// Add a neutral button to the alert box AND assign a listener for said button...

alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener(){

// click listener for box

public void onClick(DialogInterface arg0, int arg1){

// Button was clicked!!

Toast.makeText(getApplicationContext(), "Dialog closed successfully!", Toast.LENGTH_LONG).show();

}

});

// show it!!!

alertbox.show();

}

}

class WallpaperLoader extends AsyncTask {

BitmapFactory.Options mOptions;

WallpaperLoader() {

mOptions = new BitmapFactory.Options();

mOptions.inDither = false;

mOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;

}

protected Bitmap doInBackground(Integer... params) {

if (isCancelled()) return null;

try {

return BitmapFactory.decodeResource(getResources(),

mImages.get(params[0]), mOptions);

} catch (OutOfMemoryError e) {

return null;

}

}

@Override

protected void onPostExecute(Bitmap b) {

if (b == null) return;

if (!isCancelled() && !mOptions.mCancel) {

// Help the GC

if (mBitmap != null) {

mBitmap.recycle();

}

final ImageView view = mImageView;

view.setImageBitmap(b);

mBitmap = b;

final Drawable drawable = view.getDrawable();

drawable.setFilterBitmap(true);

drawable.setDither(true);

view.postInvalidate();

mLoader = null;

} else {

b.recycle();

}

}

void cancel() {

mOptions.requestCancelDecode();

super.cancel(true);

}

}

}

这是logcat:

I/ActivityManager( 59): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.death2all110.SensationalWallpapers1/.wallpaper }

I/ActivityManager( 59): Displayed activity com.death2all110.SensationalWallpapers1/.wallpaper: 474 ms (total 474 ms)

D/dalvikvm( 286): GC freed 1448 objects / 151304 bytes in 131ms

D/dalvikvm( 106): GC freed 2485 objects / 144824 bytes in 245ms

D/dalvikvm( 59): threadid=15: bogus mon 1+0>0; adjusting

D/dalvikvm( 59): GC freed 3666 objects / 207344 bytes in 360ms

D/dalvikvm( 59): GC freed 459 objects / 21096 bytes in 357ms

E/WindowManager( 286): Activity com.death2all110.SensationalWallpapers1.wallpaper has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44c0f3d0 that was originally added here

E/WindowManager( 286): android.view.WindowLeaked: Activity com.death2all110.SensationalWallpapers1.wallpaper has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44c0f3d0 that was originally added here

E/WindowManager( 286): at android.view.ViewRoot.(ViewRoot.java:227)

E/WindowManager( 286): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)

E/WindowManager( 286): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)

E/WindowManager( 286): at android.view.Window$LocalWindowManager.addView(Window.java:424)

E/WindowManager( 286): at android.app.Dialog.show(Dialog.java:239)

E/WindowManager( 286): at android.app.AlertDialog$Builder.show(AlertDialog.java:802)

E/WindowManager( 286): at com.death2all110.SensationalWallpapers1.wallpaper.onClick(wallpaper.java:244)

E/WindowManager( 286): at android.view.View.performClick(View.java:2364)

E/WindowManager( 286): at android.view.View.onTouchEvent(View.java:4179)

E/WindowManager( 286): at android.widget.TextView.onTouchEvent(TextView.java:6541)

E/WindowManager( 286): at android.view.View.dispatchTouchEvent(View.java:3709)

E/WindowManager( 286): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

E/WindowManager( 286): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

E/WindowManager( 286): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)

E/WindowManager( 286): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)

E/WindowManager( 286): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)

E/WindowManager( 286): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)

E/WindowManager( 286): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)

E/WindowManager( 286): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)

E/WindowManager( 286): at android.os.Handler.dispatchMessage(Handler.java:99)

E/WindowManager( 286): at android.os.Looper.loop(Looper.java:123)

E/WindowManager( 286): at android.app.ActivityThread.main(ActivityThread.java:4363)

E/WindowManager( 286): at java.lang.reflect.Method.invokeNative(Native Method)

E/WindowManager( 286): at java.lang.reflect.Method.invoke(Method.java:521)

E/WindowManager( 286): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)

E/WindowManager( 286): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

E/WindowManager( 286): at dalvik.system.NativeStart.main(Native Method)

D/dalvikvm( 286): GC freed 1704 objects / 168544 bytes in 330ms

它不仅具有泄漏的窗口,而且在单击该按钮时还可以设置墙纸…

任何帮助将不胜感激

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值