DigitalClock widget leaking memory when rotating display. - Android Software Development

Android 2.2 on the emulator and real devices.
I've got this to happen in a bare bones app. Just add the DigitalClock widget to the main view. Then run in the emulator pressing Ctrl + F11 to rotate the screen. In DDMS you'll see the Heap Size grow. If you do it long enough Android will kill the app.
Change the DigitalClock to a TextView with some text and no memory leak.
Anyone else seen this????
Spent all day thinking my app was bad.

Have you read this?
http://developer.android.com/resources/articles/avoiding-memory-leaks.html

Yup, read it about ten times now.
The bug is in the android source. I've filed a bug report. In short they have a 'worker' thread updating the display and used a local var to tell it to exit. This local var is called when the view is detached. I belive that the thread is causing the view and so it's parent NOT to be clean up because of the reference it has and so the detach is never called. I've written my own clock code and my memory leak has vanished.

Related

Subclassing the Start Button

Hi All,
I cracked open Remote Spy++ and started figuring out how I could go about writing a Honeycomb start menu replacement for WM5-6.1 (seen the XP Start Replacement? Same idea). Having written something similar on desktop Windows I thought it would be easy. The app is in C#/CF.
So the window hierarchy is:
Code:
- Desktop
- HHTaskBar
- (nothing !!!)
And messages of interest (in order):
Code:
WM_LBUTTONDOWN (0x201)
WM_PAINT (0xF)
WM_INITMENUPOPUP (0x117)
Okay, so forgetting about the fact that the window is opaque (I will delve into this later on), I went ahead and subclassed it to catch the WM_LBUTTONDOWN message (the others didn't stop the original from showing up). That falls over (the debugger doesn't even break into code and the device needs a hard reset). I am investigating this - although my MessageBox shows up just before it dies.
Update: Using BeginInvoke with a worker method fixes the above issue. E.g:
Code:
public IntPtr NewWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
{
if (msg == WM_LBUTTONDOWN)
{
this.BeginInvoke(new Action(DoWork));
return IntPtr.Zero;
}
return CallWindowProc(oldWndProc, hWnd, msg, wParam, lParam);;
}
private void DoWork()
{
Form2 two = new Form2();
two.Show();
}
So my question: the HHTaskBar is opaque, it has no child controls. Obviously, I don't want to subclass the battery/close/etc. buttons, and ideas on how to reliably retrieve the rect for the start button?
Or is the whole thing a hack? I suspect there is a way to do this without all this subclassing hackery. Google and forum search didn't turn up anything.
Thanks guys.
Source code
Usage: (not recommended on real device - use an emulator!) Click on button1 then click anywhere on the taskbar. Now reboot
I'd start with Quickmenu:
http://forum.xda-developers.com/showthread.php?t=471292
This app is the best start menu replacement I ever saw...
I'd only add a mixture of WKTASK's taskbar management and the ability to choose a icon for the start menu.
Thanks
twolf said:
I'd start with Quickmenu:
http://forum.xda-developers.com/showthread.php?t=471292
This app is the best start menu replacement I ever saw...
I'd only add a mixture of WKTASK's taskbar management and the ability to choose a icon for the start menu.
Click to expand...
Click to collapse
Thanks, it doesn't look like he has any source code available though. Looks like I will have to investigate more... I am not going for the drop down style (but as you said, it is really cool), I am trying to make a Honeycomb (WM 6.5) style menu.
I tried the wm6.5 honeycomb start menu... was not impressed, but maybe it had some extra something i didnt noticed... :/
I still haven't flashed my device with 6.5, but I reckon a FOSS honeycomb menu could be cool...
I think you'r on to something here. The start menu as it is in WM6.1 is pretty much useless. I would much rather have the start menu show me a application shortcut page like the one in WM6.5. Although to be honest I don't really like the honeycomb look. What's wrong with a plain old columns and rows type of thing. With the added physics scrolling/swiping stuff of course
frepe383 said:
I think you'r on to something here. The start menu as it is in WM6.1 is pretty much useless. I would much rather have the start menu show me a application shortcut page like the one in WM6.5.
Click to expand...
Click to collapse
Exactly! I am also hoping to replace that shoddy settings menu.
frepe383 said:
Although to be honest I don't really like the honeycomb look. What's wrong with a plain old columns and rows type of thing. With the added physics scrolling/swiping stuff of course
Click to expand...
Click to collapse
I think something with tabs (like Manila 2D) such as 'Programs', 'Running Programs', 'Settings' would be pretty useful. Skinning is a given, and honeycomb would be one (for the fanatics).
Update
I decided to call the tool Mead (as in the beer that contains honey ).
I was having problems with the default message pump and the hook (well, subclassed event). I am not sure which message was crashing my program, but if I use Application.Run() a native exception occurs in mscoree3_5.dll. The workaround is to create the form in the handler for the hook and show that one (it wasn't a UI thread being called from a worker, I am aware of that). So I think it must be a CF message pump bug. In any case, it works great now.
Quitting isn't all the way there yet, still some bugs (the type that will need a soft reset).
On to the UI stuff.
clickety
Excellent idea mate, but is it worth doing? the Beta 2 of 6.5 is already out and i am guessing its not long until the final version
Any news on this?
Nope
Nothing new. Just haven't had time between my job.
For now I am pinning it as the native call-in issue that the .Net CF suffers from (a documented limitation). Something isn't quite right.
I will continue to experiment, but push comes to shove, I will probably land up creating an interop library for it.
Instead of subclassing, you can just create a childwindow of HHTaskbar that is located over the start button.
Alternatively, you could suPerclass the "Explore" window class just to replace the Programs menu. Beware, that superclassing may be a bit dangerous
Interesting Idea
That is an interesting idea. When I get time I will start messing around with it.
That said I do expect some problems: again the interop call-in to .NET CF, but this may prove to work as a work-around .

[Q] Live Wallpaper Falling Images and Sizes

I am wondering how to take a bitmap image and have it drop vertically from the top of the screen to the bottom and then wrap and do it again. I can only find how to rotate it around a certain access in the help portions. I'm assuming we can use different speeds as well to do the dropping. Also, what sizes need to be set in the hdpi and so forth? It seems that 920x740 is way to big of a picture for that folder and would be a memory hog.
I've not done any wallpapers apps, but typically, to do what you intend, you'd create a thread (class derived from java.lang.Runnable) with a simple loop and a wait timer (call Thread.sleep(). As the loop iterates, send a message to a class derived from android.os.Handler. In the handler, update your coordinates and refresh your view with view.invalidate().
What has it drop? I'm curious how you have your program realize it needs to drop down and then wrap around. All I understand is how to make it rotate around a set axis point.
bearcatext said:
What has it drop? I'm curious how you have your program realize it needs to drop down and then wrap around. All I understand is how to make it rotate around a set axis point.
Click to expand...
Click to collapse
You're thinking at too high level. There is no built in api for falling objects or animating bitmaps, you need to do it yourself.
The way I do it on my doom live wallpaper is to create a java object for each character or projectile I want to draw. The object contains variables for current x and y coordinates on screen and a method to update the position for a new frame.
That makes sense, that is what I was thinking on my drive home today that maybe all it was is setting the x or y coordinates and subtracting or adding depending on how you want it to look. Thanks for the response though I think this is the second time you've helped me out so I appreciate it.

[Q] Confused with coding for layout.

Hi there, long time lurker first time poster here!
Slowly getting into android but i really cant get my head around the layouts. I would love to be able to use the AbsoluteLayouts but that isn't a good idea anymore.
Basically after some work i have managed to get a gallery working at the top of the screen. I want my app to look like this in essence: Ok can't post outside links at the moment, fair enough. Think of the android market. Icons to the left and a bit of information for each app next to it and a buy button on the right.
However i have no idea where to start off. Since i have the gallery already i have no idea how i can add things underneath it without screwing anything up.
Can anyone help? Thanks in advance!
Sorry to bump but the issue has changed, I have built an app but would like like the text to be besides the icon. Any chance someone can help? Using a linear layout.
http://img263.imageshack.us/i/sellscreen.jpg/
RED_ said:
Sorry to bump but the issue has changed, I have built an app but would like like the text to be besides the icon. Any chance someone can help? Using a linear layout.
http://img263.imageshack.us/i/sellscreen.jpg/
Click to expand...
Click to collapse
Are you using a List View? Looks like one.
How do you build up your content for the list?
In my view the best solution for your problem would be:
- Use a ListView
- Build your own ListAdapter (drived from BaseAdapter for example)
The Adapter builds the view for each item (or recycles an already built up view, the ListView handles that).
The view for each item would be a horizontal oriented LinearLayout with two items (the image and the text) and the adapter fills the layout with the information of the current item.
For better layout handling I would define the layout for the items in an extra xml file and use the LayoutInflater-Service inside the Adapter (if a view has to be built).
Hope this helps and points into a helpful direction
Devmil
Thanks for replying, managed to find a solution in the end without using ListView. Thought about moving to a RelativeLayout as its more effcient but as my app is very small anyway in the end i've just gone and used nested LinearLayouts with a textview and imageview in each one.
Ridiculously simple when you look back on it.
I was actually going to use this tutorial which does what you explained i think: http://www.anddev.org/iconified_textlist_-_the_making_of-t97.html but it left me with a force close error so that went out the window.

[Q] Can We Hide The Status Bar?

There are some apps that need run full-screen and I am finding that the status bar interferes? Example, Softick Klondike Solitaire - unfortunately a great game but the developer put the score line so that it's hidden by the HoneyComb status bar. So I'd like to hide the status bar - there may be other apps that need this too
hide system bar
I have same question - I need to develop application for internal use, but without native 3.0 navigation (back, home, apps at system bar). One way I found - set ro.sf.lcd_density to 240, system think that this is mobile phone and change interface to show top status bar without any system bar, and status bar can be removed in program, but in this case I have to rebuild program layouts and this solution is not very good for other applications.
It look like system bar placed very deep inside android 3.0 code, so now I even thinking about porting android 2.3 to Iconia A500.
Any ideas?
z4gnom said:
I have same question - I need to develop application for internal use, but without native 3.0 navigation (back, home, apps at system bar). One way I found - set ro.sf.lcd_density to 240, system think that this is mobile phone and change interface to show top status bar without any system bar, and status bar can be removed in program, but in this case I have to rebuild program layouts and this solution is not very good for other applications.
It look like system bar placed very deep inside android 3.0 code, so now I even thinking about porting android 2.3 to Iconia A500.
Any ideas?
Click to expand...
Click to collapse
Transformer has Froyo running. http://forum.xda-developers.com/showthread.php?t=1078840
If I remember correctly, some XDA member got an A500 running Froyo to.. He bought it that way, but I dont know if he still has it.
Unless 3.1 or another update provides a solution, Honeycomb is stuck with it, which is lame for for a few reasons:
Easy to touch by mistake, and is no different than having a smaller display, since the space is taken by it. At least iOS gets this right and does not take up space. One of the few things they DID get this right.
just realized that system bar can be removed by killing systemUI service, this service is hidden in "running", but can be found in "all" and can be easily stopped.
now looking for program solution to kill it and restore by me application
I know there is a setting in Launcher Pro that you can hide it on phones, I dont know if it will work with this though.
Guys keep in mind this becomes less of an issue if you can get developers to update their apps for the Honeycomb SDK. There's a mode they call "lights out" that causes the system bar to dim tremendously - which is what the youtube app does.
Maybe instead of killing it, a third party app that causes it to go to dim mode and stay there - kind of a toggle - would be more appropriate so you don't lose the use of the buttons.
http://stackoverflow.com/questions/...-lights-out-mode-in-honeycomb/5097719#5097719
cybermage1 said:
Guys keep in mind this becomes less of an issue if you can get developers to update their apps for the Honeycomb SDK. There's a mode they call "lights out" that causes the system bar to dim tremendously - which is what the youtube app does.
Maybe instead of killing it, a third party app that causes it to go to dim mode and stay there - kind of a toggle - would be more appropriate so you don't lose the use of the buttons.
http://stackoverflow.com/questions/...-lights-out-mode-in-honeycomb/5097719#5097719
Click to expand...
Click to collapse
The brightness is not the issue, but the space the black bar takes up is. Kind of like the old CRT days when the bezel was quoted as part of the screen size. For 3.1 users, a 10.1" display is really 9.6, since space is taken up by the bar.
I went back to using my gTablet for now and notice that I have more display (though a display with awful angles).
Call me stupid, but I would prefer Gingerbread on the A500:
1. Games would work fine
2. Display resolution not compromised
3. Flash works fine
4. Less issues with legacy apps and Tiger Arcade has no scaling issues.
5. Actually, no apps have scaling issues with Gingerbread, but a lot do with Honeycomb, so need to wait/hope the devs update.
Yes, defeats the purpose of the tablet centric OS, but the bar at the bottom is a waste of display space.
"Honeycomb has a hidden Gingerbread (Android 2.3) UI within it.
And it can be very easily unhidden by simply changing the LCD density. Set it to 170 or higher, reboot, and you'll see all the graphical elements of Gingerbread (lock screen, dock, app drawer, keyboard, etc.); set it to 160 or lower and the Honeycomb you're used to will greet you after a reboot."
Sent from my GT-P1000 using XDA Premium App
the status bar has the soft keys... trust me, its nice to have since there are no hard keys for this device. this was a feature that was implemented for nook color in cyanogenmod because the lack of hard keys and it made all the difference. how are you going to press back or menu if you don't have that status bar? sure you could use the softkeys app or button savior but they are inconvienient and also put stuff on your screen.
Sent from my A500 using Tapatalk
com.android.systemui
I tested some ways to kill system bar:
1. Kill by adb shell: - su; ps, look for com.android.systemui; kill <PID> - success, sys-bar removed.
2. Settings, "Sytem UI" force stop - success, sys-bar removed.
3. Root explorer, delete /system/app/systemui.apk - got circle of error messages "com.android.systemui crashed, blabla...". Reboot, tablet started without system bar, no any errors, so success.
4. My app:
Code:
android.os.Process.killProcess(android.os.Process.getUidForName("com.android.systemui"));
failed, as expected, because my app can not kill process started by another app.
5. My app:
permission - android.permission.KILL_BACKGROUND_PROCESSES
Code:
final Context context = getApplicationContext();
servMng = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
servMng.killBackgroundProcesses("com.android.systemui");
Failed, no idea why.
6. Run script in my app to execute "ps", look for PID and execute "kill", not tested.
I need to implement option 5 or 6, can anyone give me some hints why 5 failed (or how to perform 6)?
Also I need to restore system bar using my app, I tested "am start blabla", it work in some cases throwing some errors and do not work in other cases depending on moon state, I do not know exact parameters for "am", also best solution to run in from app using java, any ideas how to do it "correctly"?
Lights Out mode
Part of the honeycomb API is a Lights out mode that dims the status bar so much that you can hardly see it. If you want to see it in action, just open the Kindle app.
Until 3rd parties update their full screen apps with this API, it would be nice for a third party app to implement it.
brunes said:
Part of the honeycomb API is a Lights out mode that dims the status bar so much that you can hardly see it. If you want to see it in action, just open the Kindle app.
Until 3rd parties update their full screen apps with this API, it would be nice for a third party app to implement it.
Click to expand...
Click to collapse
1st page...
http://forum.xda-developers.com/showpost.php?p=13981583&postcount=8
~~~~~
Greetings from XOOM land.
I was brainstorming a way to hide the status bar and bring it out again when needed. It seems Windows 8 will do just that, and will use the same method I had in mind.
The idea is to use a multitouch gesture to hide it and bring it back. Touch the screen with two fingers and swipe off of the bottom of the tablet screen as if flicking the status bar away, and it kills it. Swipe up from off the screen to bring it back.
Now, implementing this would be difficult, at least for me, but I think it would be awesome to get the bar out of the way sometimes.
arrtoodeetoo said:
Now, implementing this would be difficult, at least for me, but I think it would be awesome to get the bar out of the way sometimes.
Click to expand...
Click to collapse
try to implement option (one of) described in my 1st post on this page (#11)
here is developer.android.com/guide/topics/ui/actionbar.html google description how to remove action bar in 3.0+:
manifets
<activity android:theme="@android:style/Theme.Holo.NoActionBar">
or runtime
ActionBar actionBar = getActionBar();
actionBar.hide();
manifest do nothing, and code in runtime throw "force close blabla".
Anyone was able to do it this way?
added: hmm, it look like this is another one bar at top of screen, so do not pay attention to this post
Non-programatically you can kill it in Settings under manage applications, System UI.
Therefore, would it be posible to launch this settings page, send a couple of virtual D-PAD key presses to select the force quit button, and then Return key presses to press the button. Is this possible, using a persistant IME perhaps?
kill:
Code:
Process proc = null;
try {
proc = Runtime
.getRuntime()
.exec(new String[] { "su", "-c",
"service call activity 79 s16 com.android.systemui" });
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
proc.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
restore:
Code:
Process proc = null;
try {
proc = Runtime.getRuntime().exec(
new String[] { "am", "startservice", "-n",
"com.android.systemui/.SystemUIService" });
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
proc.waitFor();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
and finally - root needed for two posts above.
credits: http://android.serverbox.ch/?p=306

[Q] Make invisible WebView emit onDraw() event

Hi all
My question will be quite strange but is what I need unfortunately. Basically I need to create an invisible WebView instance (invisible mean not showed inside the activity) and get screenshot from the showed web page every time something change in the page. No problem from get screenshot, the problem is the way to be advised when something change inside the web page currently loaded into my webview. Please note, changes I need to get can be also some images changed "on the fly" by javascript code inside the page, these kind of "events" can no be detected by standard calls like onloadpagefinished or so on (since images changed are preloaded). Another problem can be when images are fully downloaded by the browser but not yet showed in the view (in case of slow CPU per example). Normally I could to easily fix my problem by overriting the onDraw() event of the webview. Every time onDraw() event is emitted mean that something is changed into the view and I need to get new screenshot. Unfortunately my problem is onDraw() event is emitted only if the view is currently visible inside the activity. If the view is "hidden" or "offscreen" as my case the onDraw() event is not emitted since, obviously, doesn't need it. Android views lifecycle explained in the main android developer site show why this happen (the view is set in pause state once out of visible activity part). Now my question is: is there a way to "force" the view to manage onDraw() event as it would be showed but in offscreen mode like my case?
Thank you to all will can help me

Categories

Resources