i made a small app where i load a new view with TYPE_SYSTEM_OVERLAY and now i want to close it by click to a button and i got the error:
Activity com.example.viewandbutton.View2Class has leaked window android.widget.RelativeLayout@44957168 that was originally added here
i already searched for the error and found out that i have to dismiss()
the activity but dismiss only works for a Dialog object, so i have no idea how to stop the activity.
here is my code:
public class View2Class extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view2);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myView = inflater.inflate(R.layout.view2, null);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
final WindowManager wm = (WindowManager) this.getSystemService(WINDOW_SERVICE);
wm.addView(myView, params);
Button btnActivity = (Button)findViewById(R.id.button2);
btnActivity.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
finish();
}
});
}
}
thanks!