Android-android dialog叠加多层后无法完全退出

发布于 2017-02-18 01:29:05 字数 6171 浏览 1062 评论 1

package com.android.nj.applelancher;

import java.util.HashMap;
import java.util.Map;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
public class InstalledNewReceiver extends BroadcastReceiver {
private PackageManager manager;
private String Titlename;
private String packageName;
private Context mContext;
public static Map<String, String> map= new HashMap<String, String>();
private boolean first=true;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals("android.intent.action.PACKAGE_ADDED")) {
packageName = intent.getDataString().split(":")[1];
mContext=context;
try {
manager=context.getPackageManager();
PackageInfo info = manager.getPackageInfo(packageName,0);
Titlename=manager.getApplicationLabel(info.applicationInfo).toString();
System.out.println("********"+manager.getApplicationLabel(info.applicationInfo).toString());

} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
packageName= intent.getDataString().split(":")[1];
intent(Titlename, packageName);
System.out.println("发送广播成功");

}
}
private void intent(String Titlename,String packageName) {
// TODO Auto-generated method stub
Intent intent1 = new Intent();
intent1.setAction("com.intent.action.Dialog");
intent1.putExtra("Titlename",Titlename );
intent1.putExtra("packageName",packageName );
mContext.sendBroadcast(intent1);
}


}



//builder在Activity的onCreate方法中builder = new AlertDialog.Builder(myContext);
private void Dialog(String TitleName,final String packageName) {

Log.d("asdsa", "asdas");
forlderList = LancherDataBase
.getAllCountryFlags(
this,
Uri.parse("content://com.android.nj.applelancher/apkforlder"));
mWindowManager = (WindowManager) myContext
.getSystemService(Context.WINDOW_SERVICE);

LayoutInflater inflaterDl = LayoutInflater.from(myContext);
LinearLayout layout = (LinearLayout) inflaterDl.inflate(
R.layout.choosedocument, null);
builder.setCancelable(false);
builder.setView(layout);
builder.setTitle(TitleName);
final AlertDialog alert = builder.create();
lvDocList = (ListView) layout.findViewById(R.id.lvDocList);
edit=(EditText)layout.findViewById(R.id.edit);
edit.setText(TitleName);
ForlderAdapter mAppsAdapter = new ForlderAdapter(myContext,
forlderList);
lvDocList.setAdapter(mAppsAdapter);
lvDocList.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Forlders item = (Forlders) forlderList.get(arg2);
ApplicationInfo appInfo = findNewInstalled(packageName);
if (appInfo != null) {
LancherDataBase.insertMediaApps(
myContext,
appInfo,
Uri.parse("content://com.android.nj.applelancher/forlderapps"),
Integer.valueOf(item.getId()));
}
alert.dismiss();

}
});
lvDocList.setOnKeyListener(new View.OnKeyListener() {

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (packageName==null) {
alert.dismiss();
}
return false;

}
});
dialogWindow(alert);
alert.show();

}



private void dialogWindow(AlertDialog alert) {
// TODO Auto-generated method stub
Window dialogWindow = alert.getWindow();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
dialogWindow.setGravity(Gravity.CENTER);

lp.width = (int) (mWindowManager.getDefaultDisplay().getWidth() * 0.7);
lp.height = (int) (mWindowManager.getDefaultDisplay()
.getHeight() * 0.5);
lp.alpha = 0.9f;
dialogWindow.setAttributes(lp);
//System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");

}



// 接收启动Dialog的广播
public class DialogReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
String Titlename = intent.getExtras().getString("Titlename");
String packageName = intent.getExtras().getString("packageName");
System.out.println( "接收到:" + Titlename);
System.out.println("接收到:" + packageName);
Dialog(Titlename,packageName);
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜柠檬 2017-08-18 16:55:41

我觉得主要和dlg的Context有关,传入getParent的Context试下

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文