Android-android dialog叠加多层后无法完全退出
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我觉得主要和dlg的Context有关,传入getParent的Context试下