android.view.WindowLeaked: Activity has leaked window android.widget.ZoomButtonsController$Container that was originally added here - maps

Working with maps i have an activity which is launched when no connection is available and uses offline maps (MapQuest). The activity runs fine, map is shown, and all overlays, markers and so on. When the user clicks on one of the markers info window another activity is launched and at this moment i get a bunch of red error messages in the log, though the app does not crash. These messages (the init is in the title) seem to talk about the ZoomButtons and touch events. As for ZoomButtons or touch events (multitouch) in the code, there are only 2 lines :
map.setBuiltInZoomControls(true);
map.setMultiTouchControls(true);
and not any dialog…
if i write:
map.setBuiltInZoomControls(false);
map.setMultiTouchControls(false);
the red error messages disappear but of course the user cannot zoom in or out in any way…
As the error (with the "true" parameter) occurs only when launching another activity i thought that i have to add something in on pause() ie:
onPause(){
map.setBuiltInZoomControls(false);
map.setMultiTouchControls(false);
super.OnPause();
}
---- but doing so does not change anything…
Any hint??? - Thanks in advance!

Add this to your activity:
#Override
public void finish() {
ViewGroup view = (ViewGroup) getWindow().getDecorView();
view.removeAllViews();
super.finish();
}

I was having the exact same problem... thanks to you pointing out that it is caused by (likely) when the zoom controls are still visible. I tested it, and that was correct. When I pressed the back button with the zoom controls showing, it would show that leak error, if I waited until the controls faded away (they do after you stop scrolling), then there was no leak error.
A little research in WebSettings provided a method that doesn't show the zoom controls, which means it doesn't leak at anytime you want to press the back button. It does still zoom with the pinch effect though. The only disadvantage to using this method is that your controls won't show. But to me, that's worth it, since most users know about pinch zoom for all apps.
Here is what I used:
// make sure your pinch zoom is enabled
webView.getSettings().setBuiltInZoomControls(true);
// don't show the zoom controls
webView.getSettings().setDisplayZoomControls(false);

The problem with this leak window does not appear in the following version of Android 3.0 , so,you can try to do :
// enabled zoom support
getSettings().setSupportZoom(true);
getSettings().setBuiltInZoomControls(true);
// but,We should hide this button, otherwise in the version
// of Android 3 and above, there is a window leak.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// call requies API Level 11 ( Android 3.0 + )
getSettings().setDisplayZoomControls(false);
}

Related

A way to detect mouseenter vs touch click? How about using Modernizr?

I need to find a way to know if a user has used mouse hover or touch click to show and hide different menu links. What I want to do is this.
if(a user used a mouseenter or mouseleave){
$("li.mobile-show > a").hide();
$("div.hover-over").hover(function(){
$(".hover-dropdown", this).children().slideToggle();
});
}
else if(a user used touch click){
$("li.mobile-show > a").show();
$("div.hover-over").click(function(){
$(".hover-dropdown", this).children().toggle();
});
}
I tried Modernizr.mq('only all and (min-width: 768px)') to see if I can separate the table & mobile device vs computer screen, but it didn't work for large tablet devices that show the desktop view but only can use the touch feature. Help~!
It's an old trouble. Unfortunately there is no way. Not with Modernizr, not with anything.
Desktop browsers (at least major ones) has ontouchstart ('ontouchstart' in window) and whole Touch Events API.
Mobile browsers emulates mouse events.
making conclusions based on device width/dimensions is also prone to errors: many tablets has 1280, 1300 and more pixels width

(Unity3d) How do I make a "move pad" on the screen? (Mobile)

In my game you can control the character by moving left and right, jumping and attacking. (This is a mobile game) I have a button that I use to jump and attack, which is easy because I just make a button and jump or attack with OnClick(). But for moving, I don't know how to find out if the user is pressing the button, I only know when it is clicked. How can I find this out? thanks.
If you dont understand what Im trying to say, basically here is my web game: http://dugelstudios.weebly.com/weapon-plus-plus.html
(Does not work on chrome, using safari or internet exploror)
and i am porting it to mobile, and i dont know how to make the player move left and right with touch controls.
You can use other MonoBehaviour methods such as OnMouseOver to check if a button is pressed, OnMouseEnter when a user begins to press a button, and OnMouseExit to check if a user has released the button.
You can also use OnMouseUpAsButton to mimic the behaviour of Button.onClick
For draggings movements, (like movement. For example, if you have a thumbstick, or something similar for movement), you can use OnMouseDrag.
Also, completely unrelated to your question, but something you have mentioned, you can enable NPAPI to enable WebPlayer builds in Chrome.
Just paste chrome://flags/#enable-npapi in a new tab in Chrome, and click the "Enable" button to get it running
I believe there is a thumb stick asset the standard Unity asset pack that's available on the store.

Rendering issue in WPF window while dragging

I have WPF window in which my Direct3D engine render. WPF Window I start from my engine, which I develop on C++/CLI.
I have 2 displays and when I move window between them, part of the window became white and not update until I am not stop dragging it (like on screen shot).
Does somebody know how to fix this issue?
It will be hard to post code here as it is a lot of code, but I will try:
I use managed C++ and unmanaged in one project:
So, I add .Net dll`s to have access to the WPF window:
Window^ wnd = gcnew Window();
wnd->Width = 1280;
wnd->Height = 720;
wnd->Show();
WindowInteropHelper^ helper = gcnew WindowInteropHelper(wnd);
HWND WPFHwnd = (HWND)helper->Handle.ToPointer();
HINSTANCE hinstance = (HINSTANCE)Marshal::GetHINSTANCE(this->GetType()->Module).ToPointer();
engine->SetHisnstanceHWND(WPFHwnd, hinstance);
engine->InitializeSystem(wnd->ActualWidth, wnd->ActualHeight);
engine - this is unmanaged class which incapsulates all work with rendering.
Further it is a stardard d3d rendering loop. Nothing special.
It render OK, but when I resizing or move window, it draw a part of it like this (with white). When I stop resizing or moving - all OK again.
My question is: is it possible to get rid of this effect or not?
UPDATE:
I hooked the wndProc if the WPF window and try to use UpdateLayout() when size changing, but this has no effect. Seems window is not react on any intervention.
Well, it sounds like your engine is receiving WM_ERASEBKGND and it clears the window. After you release the window, it sends WM_PAINT and everything is clear again. That's what I believe might be happening.
In order to test this theory, you can handle that message and return true. Put that to your engine message handling routine:
case WM_ERASEBKGND:
{
PAINTSTRUCT pss;
BeginPaint(hWnd,&pss);
EndPaint(hWnd,&pss);
return true;
}
You can use WinSpy++ to check out what messages are delivered to underneath window. If you want to see why the background is whited out, you can do it through ProcessMonitor and see what API calls are being issued. You're probably interested in API calls that include the color white.

Silverlight: Restricting app to resize with browser zoom

Suppose I have a silverlight application. Once running in browser if I press CTRL + the app gets zoomed in and for CTRL - it gets zoomed out. Simple and common behavior;the problem is once the user zoom in the app above 100%(ZoomFactor 1) some of my controls get clipped and some gets vanished. The reason behind this may be the View placement hierarchy,which is not my headache at all. What I want is to restrict the app's Zoom In capability so that the user can not zoom it after the ZoomFactor gets larger than 1. How to do that?
I am trying following code to get the ZoomFactor:
App.Current.Host.Content.Zoomed += (s, e) =>
{
double factor=App.Current.Host.Content.ZoomFactor;
if(factor>1)
{
//restricting the app zooming when browser zoom is greater than 1.
}
};
I have searched a lot but could not find a suitable answer that could be of help. Some one please help me out.
Thanks in advance.
I think the best you can hope for is to disable zooming altogether:
App.Current.Host.Settings.EnableAutoZoom = false;
But, to be honest, by disabling zooming you are making it difficult for users with poor eyesight to use your application. The whole point of zooming in is to allow users with poor eyesight to see more easily. If zooming in breaks your application, your application has accessibility issues.
It's possible to disable/restrict zooming in browsers, see, for example, this question, but that is something that users must do in their own browsers, not something that a Silverlight application can achieve.
Add this to the HTML where your silverlight object is created:
<param name="enableautozoom" value="false">
This should allow the silverlight object to zoom in uniform and not clip any objects

Windows Forms User Control not painting well in WPF application

So, this is the issue:
I have a Windows Forms User Control that I placed in main Window of my WPF application. I override paint method of User Control. It paints ok in "ideal" case. But, after showing the control in main window, I added MessageBox. This is the code snippet:
board = new BoggleBoard(Boggle.CurrentGame.Size);
boardHost.Child = board;
MessageBox.Show("You have " + time + " seconds to find as many words as you can. Click OK when you are ready to play);
If I don't show MessageBox, everything is ok. But with the code above, after MessageBox is shown, my control is painted, but just like boardHost (Windows Form Host) has lower opacity, so I get dark area around the control. I say "like" cause I tried with
boardHost.Opacity = 1;
but it doesn't help, I still get the same thing.
What might cause this problem?
Here is a screenshot. As obvious, the dark area around the board should not be there. And it is not visible if I don't show MessageBox after it is drawn.
http://i.stack.imgur.com/RZs2W.png

Resources