[android-developers] Tips or links for efficient low CPU threads?
There's something in the app that happens in the background sporadically (daily to weekly). It's CPU intensive, but I don't want it to slow down the device. Right now, I'm creating a thread with MIN_PRIORITY, but it doesn't seem to help in anyway from the perceived slowdown of the phone while the thread is running. Thread thread = new Thread() { @Override public void run() { // cpu-intensive stuff here... } }; thread.setPriority(Thread.MIN_PRIORITY); thread.start(); Some ideas I'm thinking about: - Creating a service specifically for this thread, instead of using the existing component (Activity/Service/etc.) it was initiated from. - Object.wait()ing occasionally (although that really won't stop any CPU intensive stuff from occurring) - Putting the thread in its own service in its own process, then giving the process minimum priority. Thing is, I don't know how to make a process use less CPU time. Any tips or links on how to get a thread to use less CPU*? More broadly, to prevent some thread from slowing Android down? Thanks, -Matt * Technically it's not using less CPU - I still have to do the same things. Really, it's spreading the CPU use out over more time, so technically it's less CPU usage per unit of time. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Unable to execute dex: Section limit 1203336 exceeded by annotation
It's one of those rare moments that I've stumbled across an error that doesn't even exist on Google search (neither web search nor code search). I'm rather proud of it, in fact - it means I'm breaking stuff better than others :) [2011-10-28 17:21:19 - Dex Loader] Unable to execute dex: Section limit 1203336 exceeded by annotation [2011-10-28 17:21:19 - MyProject] Conversion to Dalvik format failed: Unable to execute dex: Section limit 1203336 exceeded by annotation Can anyone help with this? I can't find it anywhere in the source code of Android which even contains this error message. Can anyone shed some insight? Thanks, -Matt -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Is it necessary to always create a new service for every broadcast received to avoid ANRs? Implications?
Hi all. We've got a pretty large app with millions of installs. What we've noticed is that there are always ANRs reported, even in questionable conditions. For example, we see ANRs in the most simple of broadcast receivers, where there are only 4 lines of code, and no networking or file IO. The code takes 10ms to complete in normal conditions (although I've seen it as high as 60ms). Now, BroadcastReceivers are supposed to have 10,000 milliseconds to complete (10 seconds). And yet we _still_ see ANRs. So, I'm curious, are we supposed to start a service for EVERY broadcast received? For example: @Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); if (extras != null) { Intent serviceIntent = new Intent(ACTION); serviceIntent.setClass(context, TheService.class); serviceIntent.putExtras(extras); serviceIntent.putExtra(ORIGINAL_ACTION, intent.getAction()); context.startService(serviceIntent); } } And if we really are supposed to do this, I question the architecture of broadcast receivers in the first place: if we need to do this, then the system should have put them on separate threads to begin with. On the other hand, what is the overhead of creating a new service for every broadcast received? Let's say this broadcast is received 20 times a day, will that be a lot of extra CPU usage in order to create new services, just to avoid the 1 out of 100,000 chance that there could be an ANR? My initial tests showed that creating a service took about 100ms, although I admit I'd need to run the tests thousands of times over to get a better scientifically sound estimate. Thanks! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Is it necessary to always create a new service for every broadcast received to avoid ANRs? Implications?
Have you used StrictMode to confirm that you are not using networking or file I/O here? There may be file I/O under the covers in some Android API calls you're using. That is a good call, I will try that. I was thinking no. Also, bear in mind that referring to classes other than the BroadcastReceiver itself may involve file I/O. We know that unreferenced classes are not loaded into the Dalvik VM, which is why we can conditionally load classes based on Build.VERSION.SDK_INT. What isn't clear to me is whether the class is already in RAM when the process started but just wasn't hooked into Dalvik, or whether the class is loaded off of flash at the time we refer to it. Anybody know what the rule is here? Yes, but if this theory holds water, then the only solution is that you must always use a service, or never reference classes or APIs outside of the BroadcastReceiver (which isn't documented). A broadcast receiver would have to either access files, the network, or Android APIs; otherwise it's just a waste of CPU. Now, BroadcastReceivers are supposed to have 10,000 milliseconds to complete (10 seconds). And yet we _still_ see ANRs. So, I'm curious, are we supposed to start a service for EVERY broadcast received? Not that I'm aware of. Well, the process will already be set up, since your BroadcastReceiver is running. 100ms seems plausible, though I haven't run those sorts of tests yet either. I think we're coming to the conclusion that there is nothing that should be done about the occasional random ANR in a broadcast receiver that takes at most 100 ms and has 10,000 ms to complete. It's randomness. I suspect that the Android platform is simply architected in a way to where it is expected that .1% of users monthly to experience ANRs without the application doing anything wrong. I suppose that's what you get when you have an OS using garbage collection.* Unfortunately, I think it casts a bad light on Android phones. This means that regular Android phones running properly written apps will still get ANRs. :( -Matt * Remember how the old Java sources always used to have the odd warning: not designed or intended for use in the design, construction, operation or maintenance of any nuclear facility. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Do existing scheduled items on the AlarmManager get cancelled after an application update from the Marketplace?
Hi all. I was wondering what would happen in the following scenario: Your application schedules a service or any type of pending event on the AlarmManager. Let's say it repeats every 24 hours at noon. If an application update is available, and the user updates the application at 10 AM through the Marketplace app, does that update remove all scheduled events from the AlarmManager? Or will the service still start at noon? I understand that there could be complications if the pending events aren't removed: the application update could have completely removed the service that would have been started. But in that case, the AlarmManager would just catch an exception when it tries to start the service and ignore it. On the other hand, if the AlarmManager DOES remove all the scheduled events, how is your application supposed to restart the services? 1. You can't tell on the application startup whether or not your previous services have been cancelled, because there is no way for your application to query AlarmManager to see if your services are still scheduled or not. 2. You can't blindly start your service at app startup, because you don't want a service that is supposed to run every 24 hours to run 5 times a day if the user starts your app 5 times that day. 3. Even if you persist a flag to disk indicating that your service is running, your application doesn't receive an event that the service was stopped (that I know of), so you can't turn that flag off if the service is cancelled during an application update. Does anyone have any advice on how to reliably keep a service scheduled consistently after an application update? Thanks! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Do Alarms Trigger Upon Creation
The AlarmManager setRepeating() methods include parameters for 1. when it starts, and 2. how often it repeats. http://developer.android.com/reference/android/app/AlarmManager.html On Feb 25, 11:37 am, Jake Colman col...@ppllc.com wrote: If I create an alarm on a repeat interval of, say, 60 minutes, will it trigger upon creation and then every 60 minutes thereafter or only trigger when the interval has elapsed? -- Jake Colman -- Android Tinkerer -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Is it possible to clear the task stack without finishing/destroying the activities in the stack?
I have a base group of activities. Let's call them A1, A2, and A3. When the user switches between these activities, they are at the bottom of the app. When they press the BACK button in either A1, A2 , or A3, they leave the app (or task). An easy way to visualize this is a tab activity, such as the phone app. When you switch tabs in the phone app, the individual activities are not finished. This is important because if you scroll down in your call log, and then change tabs to your contacts, and then return to the call log, the activity is still in the same state, with the list being scrolled down. I am trying to find a way to mimic this behavior, but without the use of a TabActivity. The problem I've run into is that when you use the various task and intent flags such as FLAG_ACTIVITY_SINGLE_TOP, FLAG_ACTIVITY_NEW_TASK, and/or FLAG_ACTIVITY_CLEAR_TOP, is that you can mimic the navigational functionality, but the other tasks are finished() and destroyed when you switch. This is not optimal; when switching back and forth between the tabs/activities, there is no good reason to destroy and re-create the activities. (In the above example, the call log wouldn't be scrolled down to the same spot because it was destroyed and recreated) I would love to find a simple flag such as FLAG_CLEAR_TASK_STACK. That's all I need, although it doesn't exist from what I can tell. I wonder if the only way to accomplish this is to do what TabActivities do themselves and create my own ActivityGroup? I'm sure that would solve the problem, but it seems to be overkill to just solve this problem. Thanks! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: setTextColor dynamically, major phail
The following do not work: myDate.setTextColor(0x00FF); This app has examples of dynamically changing text color. http://www.androidengineer.com/2010/08/easy-method-for-formatting-android.html -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Is it possible to clear the task stack without finishing/destroying the activities in the stack?
When switching back and forth between activities, by default, they are not destroyed and recreated - unless necessary. This is irrelevant. Activities, by default, are destroyed when clearing the task. If you are concerned with maintaining state (like a list view's scroll position), you need to review the Activity Lifecycle. Although it is possible to maintain the state after finishing activities, that's not what I'm asking about. The idea is to clear the navigation stack, which is called the Task in Android, when navigating to certain Activities, without finishing other Activities. To keep the Task empty, the Activities are indeed destroyed by Android. What I want is to keep the Task empty without destroying the Activities. This is so that pressing BACK will exit the application on any of these tab activities, but that switching between the tab activities won't destroy and recreate them. In a purely theoretical sense, these tab activities would share the same position 0 in the stack. The TabActivity uses an ActivityGroup to accomplish this. What I want to know is if there is a way to flag either the Activity in the manifest, or the Intent which starts the Activity, to accomplish this. ... After giving this some thought, I think that this is not possible, and this is my theory on why. I theorize that Android internally keeps track of which Activities are open inside of a process with tasks: a process has a ListTask. A Task correspondingly would have a StackActivity. This is the only data collection which contains available Activities; otherwise the process would require two data collections to track: a ListTask and a ListActivity. Or, a Task would have a StackActivity of Activities on the navigation stack and a ListActivity of unfinished Activities not on the navigation stack. Having two data collections to track, while not impossible, would be slightly messier. If it is the case that the only data collection of Activities a process has is ListTask and the Task correspondingly only has a StackActivity, and if the OS cleared the task without finishing() the Activities, then it would have no reference to the non- finished Activities, so there would be no way for Android to find an Activity that is already instantiated and non-finished. Essentially, for this to work, a Task would have to have both a navigation stack of non-finished Activities Stack Activity and a list of unfinished Activities ListActivity to support this framework. In any case, even if the above theory is incorrect, I can't find the equivalent of a CLEAR_NAVIGATION_STACK flag which doesn't finish the Activities in a Task. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: dex in ant with external libs in SDK tools R8
AHH! This latest update to Android SDK v8 has made my life hell. 1. The change that makes the compiler fail when strings have multiple formatter specifications (%d, %s, etc.) without position arguments (%1d, %2s, etc.) is new. This means that ALL PREVIOUS TAGS/BRANCHES/ ETC. IN THE REPOSITORY HISTORY WILL NO LONGER BUILD. The app will build but then crash during runtime because of the missing libs. 2. Confirmed that this is a bug, introduced in Android SDK Tools revision 8. The Ant builds no longer work with external libraries. Interestingly enough, if you build your project in release mode with debuggable=false in your manifest, the ProGuard obfuscation step will include your external libraries and you won't see this problem. However, when ProGuard isn't used, you'll see this problem. Andreas, I'm not sure where you added that line path refid=jar.libs.ref /. I need to make this fix in the build.xml file, not in the Android SDK Tools directory, because this change needs to work on all of my team's machines and the build machine. I'll try to find a solution and post it here. -- Matt -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: dex in ant with external libs in SDK tools R8
Andreas, I'm not sure where you added that line path refid=jar.libs.ref /. I need to make this fix in the build.xml file, not in the Android SDK Tools directory, because this change needs to work on all of my team's machines and the build machine. I'll try to find a solution and post it here. I've found the problem. In the latest version of the Android SDK Tools (v8), the ${sdk}/tools/ant/main_rules.xml contains the build targets for regular Android projects built with Ant. In this file, inside the macrodef name=dex-helper element, there is a command which calls the application dx which creates the classes.dex file for you. It is missing the external libs when called from the -dex target. Right now, the ERRONEOUS program is run like: java -Xmx1024M -Djava.ext.dirs=lib\ -jar lib\dx.jar --dex --output=C: \xxx\bin\classes.dex C:\xxx\bin\classes However, it SHOULD be run including the external jar libraries as the source, along with the java class files: java -Xmx1024M -Djava.ext.dirs=lib\ -jar lib\dx.jar --dex --output=C: \xxx\bin\classes.dex C:\xxx\bin\classes c:\xxx\lib\external_lib.jar In order to fix this, you can do two things. One, is to change the $ {sdk}/tools/ant/main_rules.xml file yourself by changing the -dex target from: if condition=${manifest.hasCode} then dex-helper / /then else echohasCode = false. Skipping.../echo /else /if to: if condition=${manifest.hasCode} then dex-helper external-libs path refid=jar.libs.ref / /external-libs /dex-helper /then else echohasCode = false. Skipping.../echo /else /if Although that solution will work for most developers, it will not work if you need to propagate this fix across all team members working on the project. As an alternative, you can fix it in your own project's build file (build.xml) by ensuring that the external .jar files are included in the input directory. You can do this by copying the .jar files to the dex input directory before the dex target is called: target name=-pre-compile !-- To fix a bug in Android SDK Tools v8, we need to copy the external libraries to the binary output directory, so that the .jar is included by the DX compiler. This will be unnecessary in the future when the bug is fixed; see http://code.google.com/p/android/issues/detail?id=13091. -- copy todir=${out.classes.absolute.dir} fileset dir=${jar.libs.absolute.dir}/ /copy /target If you fix it in your own build.xml file, then everyone who checks out the project will be able to build the project correctly, without having to change the SDK Tools local to their machine. This is documented in the bug here: http://code.google.com/p/android/issues/detail?id=13091 -- Matt Quigley www.androidengineer.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: dex in ant with external libs in SDK tools R8
Although that solution will work for most developers, it will not work if you need to propagate this fix across all team members working on the project. As an alternative, you can fix it in your own project's build file (build.xml) by ensuring that the external .jar files are included in the input directory. You can do this by copying the .jar files to the dex input directory before the dex target is called: I posted too quickly... the more appropriate thing to do is to copy the external library jars ONLY when ProGuard is disabled, otherwise you'll get two copies of the class files in the resulting package. target name=-pre-compile !-- To fix a bug in Android SDK Tools v8, we need to copy the external libraries to the binary output directory, so that the .jar is included by the DX compiler. -- if condition=${proguard.enabled} then echo message=Not copying external .JAR files because ProGuard is enabled./ /then else echo message=Copying external .JAR files because ProGuard is not enabled./ copy todir=${out.classes.absolute.dir} fileset dir=${jar.libs.absolute.dir}/ /copy /else /if /target -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: dex in ant with external libs in SDK tools R8
The Ant builds no longer work with external libraries. Make sure you are on Ant 1.8.1. On Dec 10, 2:21 pm, Xavier Ducrohet x...@android.com wrote: Yes. this is a requirement that fell through the release notes. We're adding code to detect the Ant version at compile time and fail hard if it's too low. Aww crap... I just spent way too long fixing it and entering a bug. So are you saying that the bug at http://code.google.com/p/android/issues/detail?id=13091 won't occur if I upgrade my Ant from 1.7.1 to 1.8.1? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Reasoning behind disabling certain ProGuard optimizations?
In the latest Android SDK Tools (revision 8), ProGuard has been integrated into the ant build. This is easier to set up than it was before (http://www.androidengineer.com/2010/07/optimizing-obfuscating- and-shrinking.html), but I'm curious about the optimizations that are disabled by default. From the proguard.cfg file created with android update project -p .: -optimizations !code/simplification/arithmetic,!field/*,!class/merging/ * #1: code/simplification/arithmetic: This removes things like turning 3 + 3 into 6. A shame, but understandable, because there are much more complicated optimizations to the byte code that Dalvik doesn't handle well. This one is completely understood. #2: !field/*: This refers to the following: field/removal/writeonly - Removes write-only fields. field/marking/private - Marks fields as private, whenever possible. field/propagation/value - Propagates the values of fields across methods. #3: !class/merging/*: This disables merging two or more classes horizontally or vertically (in the same class hierarchy). The question here is, why would #2 and #3 give Android or Dalvik any problems? The classes are valid Java classes in the end. I suspect the answer for #2 is that projects built into Android require that the R.* classes to remain intact. However, this is NOT the case for private apps created by developers, unless they use introspection to access those fields. There is no need for the R class at all; all of the constants of that class can be propagated into whomever uses them, and the the R class can be removed. For #3, this might have something to do with the fact that Views referenced in layout .xml files are dynamically created at runtime by reflection, and maybe merging these classes together messes them up. But isn't that prevented by -keep public class * extends **View? For over a year I've been obfuscating my app and #2 and #3 have never been used. I don't plan on using them from now on, either. Unless, someone can clarify why I shouldn't be enabling #2 and #3? Thanks! -Matt P.S. I would recommend adding the following to the next version of the Android SDK Tool's automatically generated proguard.cfg file: # Keep classes which are not directly referenced by code, but referenced by layout files. -keep public class * extends **View { public init(android.content.Context); public init(android.content.Context, android.util.AttributeSet); public init(android.content.Context, android.util.AttributeSet, int); public void set*(...); } This prevents classes which extend View, TextView, etc. classes from being renamed. This will avoid ClassNotFoundExceptions when developers use custom View classes referenced in their layout files. It will hit some false positives (i.e. a class which ends with View may not actually be used as such), but that is acceptable IMHO, and can be easily changed by a developer as needed. An alternative is to use -keep public class * extends android.view.View, which removes all false positives, but will add some missed cases, such as a class which extends TextView. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: SDK 2.3: Get Multiple substitutions specified in non-positional format error
To all the various responses: 1. To the guys asking about plurals, have you seen http://developer.android.com/guide/topics/resources/string-resource.html#Plurals ? 2. To the guys who think the errors for the multiple formatters is over the top... it isn't just over the top, it has really screwed us over! I guarantee you what happened is that someone working with Google wasn't using positional formatters in the strings, and in the latest batch of translations, one of the positions was supposed to be moved and it wasn't. So, one person at Google (maybe Romain? he was talking about it's reasoning earlier) decided that it should be an error for all people everywhere, because of the screwup in the translation. It wouldn't have been a problem if this was the way it started out when Android was initially released, but what actually happened is that the innocent upgrading of the latest SDK (even though you're supposed to be able to use any older API levels you want) has made all of our projects break. It has made a lot of unnecessary work for me and my team. We've got multiple projects with a build machine, everything's F'd now. If you upgrade the SDK Tools on the build machine, half the projects don't release. Not only that, the same project can have multiple branches in git. Even as good as git's merging abilities are, after changing all of the various strings in various branches (which change often), now the strings.xml is hell to merge when you add in formatted=false to the line. To create a hotfix on an older version, we are forced to make manual changes on these old branches. To put it succinctly, this seemingly innocuous feature to error on all these types of strings whereas before it didn't has invalidated every old build in our system, period. There's no way to turn it off, even if you set the API level to 1. We can no longer build anything before 12/6/2010, without creating a special separate build machine which has an old version of the tools on it. Okay, this rant is over, have a good rest of your day! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Why on earth do the Android Ant tools use javac with encoding=ascii?
We are externalizing all of our text; we support both English and Spanish. There still are valid occurrences of non-ascii strings appearing in .java files. Nonetheless, this is not a feature this is a bug. Ascii is neither the default encoding of Java, nor even the correct encoding to use for Android applications. I created a bug here: http://code.google.com/p/android/issues/detail?id=12924 On Dec 2, 9:30 pm, Zsolt Vasvari zvasv...@gmail.com wrote: Totally agree. I just changed all my instances of non-ASCII characters to use the \u notation (I have a few for currency codes and for a minus sign where I use a long-dash for asthetic reasons instead of a regular -). That said, having non-ASCII in your source file probably means that you should be externalizing text, unless you write comments in your native language, but guessing by your name, that's not the case. On Dec 3, 1:18 am, Matt Quigley matthew.quig...@gmail.com wrote: First of all, I find it odd that the encoding is even specified at all. Why not just leave it as the default system encoding? Secondly, if one is going to specify an encoding, then it should NOT be ascii. It should be UTF-8. After all, the files themselves are not ascii, they are UTF-8 (or Cp1252). Thirdly, the Eclipse compiler does not use ascii. This is why you see tons of warning: unmappable character for encoding ascii when using ant to compile your project, but you don't see that with Eclipse. I believe this isn't just a nuance, I believe it to be a bug. If you use a non-ascii character, such as a vowel with an accent in any .java or .xml file, the compiler may not interpret those PERFECTLY VALID characters correctly. One can, of course, change it yourself, by looking in sdk.dir/tools/ ant, and removing all occurrences of encoding=ascii, but if you have to do this to make your programs correct, then this indicates a bug in the toolset. (At the very least, it should be a changeable property, such as ${java.encoding}. But, I would like to know if there is a good reason for overriding the default Java encoding. Thanks, -Matt -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Dear Google - Please stop breaking my app with every update
Dear Google, You are really cool and all. You must be working really hard on this Android thing because I see updates every few months. But every time you come out with a new update to the Android SDK, you break my app. In strange ways, too! A while back there was this new feature to the Marketplace where uses-feature's default values would be different based on which API level you built it with. Not only did I found out, post release, that my app didn't show up on 3 out of the dozen or so phones I support, there was no warning that that was going to happen when I updated my SDK... I had to search for it after the fact. Then you broke all my build files, not once, but twice, on the last two updates. Did you have to rename every variable in the Ant build tools? Did you have to do it AGAIN with the next subsequent version of the SDK tools? (Geesh, twice in a row.. API level 7 and API level 8) Well, I just got my build working with the latest version of the SDK tools yesterday, which was SDK Tools version 7. Now, you've come out with a new update today, API level 9 and SDK Tools level 8. But you've broken my app's build, AGAIN. You added a new attribute, formatted, to the string element (a la strings.xml), and now my app doesn't build. Not only that, but you have presumed that I need positional formatters like %1d instead of just %d, and instead of being backwards compatible you've broken my build, again. I already knew that positional formatters were necessary SOMETIMES, but you have (for my own good, I'm sure) broken my build so that, if I ever translate my app into certain languages with certain string constructs, that I am sure to use positional formatters. I mean, I wouldn't have found that on my own or anything, because nobody QAs apps, so thank you for your kind help. And as is typical, the documentation mentions nothing about the new formatted attribute to the string element: http://developer.android.com/guide/topics/resources/string-resource.html Google, can we keep Android as a tool that is meant for professionals to use, instead of some whack-a-mole approach to features and compatibility? Can you keep future SDK Tools and API SDK Level from breaking older stuff, so that they remain backwards compatible? Thanks! Stay cool, -Matt P.S. Stop presuming all files are encoded in ascii, that's just ridiculous, leave it as the default encoding or let us override it. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: SDK 2.3: Get Multiple substitutions specified in non-positional format error
On Dec 6, 3:08 pm, Romain Guy romain...@android.com wrote: It wouldn't. What if you translate your app in a language where the second value should appear first? The translation would be $2%s $1%s and the code wouldn't change. That may be the case, sometimes, somewhere. It isn't all the time. There may have been some developers giving strings to a translation company who returned the string translations and didn't tell the developers that the order of %s and %s was different, and the software company didn't have any QA in place to catch this, so some strings appeared funny for that particular translation. I don't think the answer to solve this problem, that probably happened once to someone, with a build error instead of a warning. And please, it would be nice if someone could take the time to document what exactly the formatted attribute of the string element means. http://developer.android.com/guide/topics/resources/string-resource.html Thanks, -Matt -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: SDK 2.3: Get Multiple substitutions specified in non-positional format error
On Dec 6, 4:13 pm, Daniel velaz...@gmail.com wrote: What would be the proper way of outputting a % sign, it's giving me this error on a regular string saying 3% Outputting just a % sign? Probably %%. Or, you can leave it as 3% and add formatted=false. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Dear Google - Please stop breaking my app with every update
On Dec 6, 4:25 pm, Xavier Ducrohet x...@android.com wrote: At this time we really haven't committed to keep the rules compatible if you go in and change/override stuff. If you need extensibility you should let us now what and we'll add it. Okay, that's fair I suppose. That previous problem had to do with ant scripts, and this latest one about the string formatted attribute has to do with the resource compiler. In general, I worry about non- backwards compatibility. We don't want to be supporting Internet Explorer 6 for another 10 years! Now that ProGuard is included in the latest build, I probably don't need to override anything. Hopefully the hook targets -pre-build, - pre-compile, and -post-compile, we probably don't need to override anything. (P.S. what about a -post-build target, so I can ZIP up my signed .APK with some other relevant files to the build?) Yes, I already replied to your other message. It is overridable now. I even just checked in a fix for it:https://review.source.android.com/#change,19349 Oh sweet! You rock. Perfect timing, that it got in with the latest release. Thanks, -Matt -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Why on earth do the Android Ant tools use javac with encoding=ascii?
First of all, I find it odd that the encoding is even specified at all. Why not just leave it as the default system encoding? Secondly, if one is going to specify an encoding, then it should NOT be ascii. It should be UTF-8. After all, the files themselves are not ascii, they are UTF-8 (or Cp1252). Thirdly, the Eclipse compiler does not use ascii. This is why you see tons of warning: unmappable character for encoding ascii when using ant to compile your project, but you don't see that with Eclipse. I believe this isn't just a nuance, I believe it to be a bug. If you use a non-ascii character, such as a vowel with an accent in any .java or .xml file, the compiler may not interpret those PERFECTLY VALID characters correctly. One can, of course, change it yourself, by looking in sdk.dir/tools/ ant, and removing all occurrences of encoding=ascii, but if you have to do this to make your programs correct, then this indicates a bug in the toolset. (At the very least, it should be a changeable property, such as ${java.encoding}. But, I would like to know if there is a good reason for overriding the default Java encoding. Thanks, -Matt -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] When is the appropriate time to use separate processes?
Hi all. I have read all about having separate processes for different Application components, and how to use them. I am curious, what are some appropriate use cases for when an application should actually use separate processes? It seems to me, the main advantage to using separate processes is to make the different portions of your app more easily killable by the OS. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: sendBroadcast in IntentServicenot non-re-entrant?
I believe that you are expecting the IntentServices to act like threads. You will not have multiple instances of an IntentService run at the same time. From the documentation at http://developer.android.com/reference/android/app/IntentService.html: All requests are handled on a single worker thread -- they may take as long as necessary (and will not block the application's main loop), but only one request will be processed at a time. I admit, the IntentService's documentation isn't very clear. But in any case, if you have multiple starts of an IntentService, they will happen one after the other, and not at the same time. -Matt On Nov 4, 1:54 pm, Bret Foreman bret.fore...@gmail.com wrote: I'm trying an experiment where an Activity makes a number of consecutive calls to an IntentService. Each call kicks off some background work that finishes in a few seconds. So there are multiple concurrent instances of the IntentService running. All the instances finish at around the same time and each one does a sendBroadcast to return a message to the Activity that it's finished. When this happens, about 30% of the broadcast intents never get back to the Activity's registered receiver. It looks as if there is some static state inside the IntentService class that is in conflict when there are multiple invocations running and they are all calling sendBroadcast at about the same time. In other words, sendBroadcast appears to be non-re-entrant. I'd like to package up this example for submission to b.android.com but before I do, I'd like to find out a few things from this forum: 1) Is this a known bug? 2) Is this expected behavior (ie not a bug)? 3) Has anyone seen anything like this or another case where the IntentService worked correctly when used in this way? -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: When is the appropriate time to use separate processes?
Hi all. I have read all about having separate processes for different Application components, and how to use them. I am curious, what are some appropriate use cases for when an application should actually use separate processes? I'm not sure there are any for the vast majority of Android apps. Well, okay, but the question is... What are some appropriate use cases for when an application should actually use separate processes? It seems to me, the main advantage to using separate processes is to make the different portions of your app more easily killable by the OS. No offense, but taking up double memory to allow the OS to more easily kill half of it is like chopping down trees to give you more paper for recycling. There might be valid reasons for using more than one process -- though I don't know of any -- but I feel fairly confident this is not one of them. Using two processes would take up more total memory when they were active at the same time. However, sometimes components are foreground and background and therefore are active in, some components are active frequently or all the time in the background such as Services and BroadcastReceivers, and some only when in the foreground such as an Activity. Some components take 5000% more memory than others. It would indeed be stupid to double memory to allow the OS to more easily kill half of it, but that is not what I was implying. I can't think of a good reason to use separate processes, other than making portions of your app easily killable (such as background services). I'd like to hear other developers' experiences with doing so, or framework engineers' rationale on their purpose. -Matt -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Can anyone recommend a good OpenGL ES book?
I'm looking for a good book to buy to help me with OpenGL ES. This is obviously going to be for Android, but I suppose the benefits will spill over to iPhone development too. Although I'm not specifically opposed to a general OpenGL book, I'm not going to be using it on my desktop (at least not professionally). Wouldn't hurt to throw a few good online references too, although what I've found with online tutorials is that they teach a code snippet but not the whole picture. Or, they don't target ES (embedded systems, like Android). Thanks, -Matt -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Android source code (complete)
There are many more project directories that make up the Android source. /platform/frameworks/base is just one of many on http://android.git.kernel.org/. I don't know off hand where ServiceManager.java is, but it's there somewhere. -Matt On Nov 2, 1:25 am, adithya 24adit...@gmail.com wrote: Hi all, I have downloaded some amount of android source code (for Bluetooth API's, wifi API's,etc)..I was just browsing through Bluetooth source code in eclipse and bumped on this ServiceManager class whose source code i couldn't read !! When i browsed through the android.jar i couldn't see the source code for few packages like java.nio ,etc.. I have downloaded git for windows and whatever source code i have is through the following command : git clone git://source.android.com/platform/frameworks/base and put all the java files into a 'sources' folder which worked.. How can i get the source code for aforementioned classes ?? Thanks, Adithya. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Can anyone recommend a good OpenGL ES book?
A little. I took a 3D graphics class in college. I've actually been drawing lines, squares, and textures on Android already. The thing is, I'd like to know how to start from scratch, instead of starting from a tutorial. Basically, I'd like to KNOW why I'm writing the code I write. It's just a yucky feeling (to me, at least) to not know why a line of code is there. On Nov 2, 7:53 pm, Leigh McRae leigh.mc...@lonedwarfgames.com wrote: Do you have any 3d experience? On 11/2/2010 7:28 PM, Matt Quigley wrote: I'm looking for a good book to buy to help me with OpenGL ES. This is obviously going to be for Android, but I suppose the benefits will spill over to iPhone development too. Although I'm not specifically opposed to a general OpenGL book, I'm not going to be using it on my desktop (at least not professionally). Wouldn't hurt to throw a few good online references too, although what I've found with online tutorials is that they teach a code snippet but not the whole picture. Or, they don't target ES (embedded systems, like Android). Thanks, -Matt -- Leigh McRaewww.lonedwarfgames.com -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: OpenGL ES 2D and 3D mixed graphics?
Thanks for the advice, guys. Googling OpenGL HUD is a step in the right direction for anyone else looking to do this. Here's some quick code: private void viewOrtho2(GL10 gl, int x, int y) { // Set Up An Ortho View gl.glDisable(GL10.GL_DEPTH_TEST); gl.glMatrixMode(GL10.GL_PROJECTION); // Select Projection gl.glPushMatrix(); // Push The Matrix gl.glLoadIdentity(); // Reset The Matrix gl.glOrthof(0, x, 0, y, -5, 1); // Select Ortho Mode gl.glMatrixMode(GL10.GL_MODELVIEW); // Select Modelview Matrix gl.glLoadIdentity(); // Reset The Matrix // This fixes some 2D perspective issues gl.glTranslatef(0.375f, 0.375f, 0.375f); } Test it out with some squares: private void testmethod(GL10 gl) { ByteBuffer vbb = ByteBuffer.allocateDirect(squareVertices.length * 4); vbb.order(ByteOrder.nativeOrder()); FloatBuffer vertexBuffer = vbb.asFloatBuffer(); vertexBuffer.put(squareVertices); vertexBuffer.position(0); gl.glLineWidth(3.0f); gl.glColor4f(0.0f, 0.0f, 1.0f, 1.0f); // blue gl.glTranslatef(5.0f, 0.0f, 0.0f); gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4); gl.glTranslatef(100.0f, 0.0f, 0.0f); gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); // Red gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4); gl.glTranslatef(100.0f, 0.0f, 0.0f); gl.glColor4f(1.0f, 1.0f, 0.0f, 1.0f); // Yellow gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4); // Switch back to the previous view gl.glEnable(GL10.GL_DEPTH_TEST); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL10.GL_MODELVIEW); } This essentially shows how, even in a 3D display, you can switch to a 2D projection. Key lines of code: gl.glOrthof(0, x, 0, y, -5, 1); // Select Ortho Mode by mapping (0,0)- (width,height) (320x480) gl.glDisable(GL10.GL_DEPTH_TEST); // Remove 3D depth testing -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] OpenGL ES 2D and 3D mixed graphics?
I'm making a 2D game, with sprites drawn using the glDrawTexfOES() method. I'm wondering if there are ways to draw things like lines and squares along side this. Now, I know that technically there's nothing stopping me from drawing 3D cubes and such. But, you see, glDrawTexfOES draws using pixel coordinates, i.e. draw texture at 30,30. What I'd like is a similar approach to boxes and lines, using pixel coordinates, i.e. draw line from (5,5) to (10,10). Is this possible? I don't want to simulate 3D coordinates because it would be very hard to try to get the camera and perspective in such a perfect way where I could say draw cube from (5,5,0) to (10,10,0), as well as from (300,300,0) to (310, 310, 0), with no perspective warping in the different corners. (Also, as a backup plan I can always create my line and box effects with sprite textures as well, but I thought I'd ask) -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to remove an activity from the navigation stack (without finishing)
I'm sorry I've confused everyone, I will try to explain myself more. First of all, ignore anything related to downloading data from the network. Of course you download data in a separate thread or service. This question has nothing to do with that. What I'm trying to do is emulate tabs. I'm not using TabActivity because there are serious limitations on how you can customize a TabActivity, while still having an application be compatible with Android 1.6. Tabs are a group of activities. You can click on the various tabs as many times as you want, and it switches to that tab's activity. The activities do not finish() when you switch tabs. Also, when you press back, you leave the entire group of tabs, instead of going back to a previous tab. Now, in order to emulate tabs, for simplicity's sake let's say I have 4 buttons on each activity (I'll call each activity a tab now, even though they're not technically Android tabs without actually using TabActivity). When you click a button, it shows another activity/tab. The problem is that when you go to another activity/tab and press back, you return to the first tab. This is not the desired behavior; when they press back they should leave the entire app. One way to solve this navigation problem is to call finish() on the current activity when the user clicks a button to switch tabs. I was hoping to avoid calling finish(), but it seems like that must be my only choice. Otherwise I would have to try to use android.app.LocalActivityManager, which is what a TabActivity/ ActivityGroup uses. In essence, I don't think there's a simple way to fix that navigation problem without using finish(). What I believe my choices are: 1. Call finish() on the previous activity when switching activities. 2. Use a LocalActivityManager. 3. Use some CLEAR_TASK_STACK flag when switching activities. Since #3 doesn't seem to exist, I'm going with #1. Thanks everyone. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to remove an activity from the navigation stack (without finishing)
On Aug 12, 2:34 pm, Mark Murphy mmur...@commonsware.com wrote: Why? Why not views and a ViewSwitcher? On Aug 12, 2:42 pm, TreKing treking...@gmail.com wrote: 4. Use one single activity with four components of your own design. Your main layout can have the four tab buttons and a space beneath (or above) for the current component. When you hit a button, you load up the correct component along with it's associated layout in the designated space. I'm upgrading an application, not creating a new one. The activities (code) already exist. In fact, though, your solutions would both work exactly how I would like them to, and they're great ideas. I'm not going to redesign everything, though. On Aug 12, 2:42 pm, TreKing treking...@gmail.com wrote: What's wrong with calling finish() ? I assume the OP wants to avoid the overhead of destroying and reloading an Activity every time. If the user tries to switch tabs quickly, it will be very noticeable. Exactly! Oh well. It ends up being about 1 to 2 seconds to switch with finish(), vs. 0.5 to 1 second to switch with regular tabs. In the end, we're not talking about a game where split second responsiveness is necessary. Thanks for the discussion, everyone. -Matt -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: How to remove an activity from the navigation stack (without finishing)
On Aug 10, 6:13 pm, Streets Of Boston flyingdutc...@gmail.com wrote: Load the network data from a background thread or even a (background) service, not from your activity. For an even better user-experience, you may want to consider caching the data as well (if that's possible). OK, well we actually do cache the data. And of course data is loaded from a background thread; otherwise you would easily get an ANR (Application Not Responding). I just thought that going into that discussion might distract from my real question. :) On Aug 10, 8:16 pm, TreKing treking...@gmail.com wrote: I'm utterly confused as to why you would need an Activity removed from the stack but remaining in memory ... Think about this: the onPause() would be called on the activity when you leave it, but not onDestroy(). When you return, the onResume() is called, but not onCreate(). The stack is the Android task, or list of activities that the user has navigated to which will appear when you press the back key. I was hoping that it would be possible to clear this stack in memory, so that when a user presses back they don't go to those certain activities. In any case, the problem is easily solved by calling finish() in the click event of the button which navigates between activities. I was just hoping for a solution that didn't have to finish the activity, which ends it and removes it from memory. Thanks anyways, everyone! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] How to remove an activity from the navigation stack (without finishing)
Let's say you have a TabActivity with activities A1, A2, A3, and A4. When you click on the different tabs, no matter how many times you navigate between them, when you press the back key you leave the entire tab group, instead of navigating to a previous tab. My problem is, I am not using an actual TabActivity. Does anyone know how to specify to Android that I'd like to mimic that behavior with a group of activities? The classic solution (that I know of) would to simply finish() the activity as you navigate away from it. That clears the stack, so that when you went from A1 and then to A2, and pressed back, you don't go back to A1. The problem with using finish() is that I don't want the activity removed from memory. These activities load data from the network, so unless the data was cached, it would need to be reloaded on every navigation which would not be a great user experience. I was looking at the flags which you can specify how to change this behavior: http://developer.android.com/guide/topics/fundamentals.html#acttask I tried using these: intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); But no matter what, when I go from A1 to A2 and press back, I always get back to A1. Can anyone help in trying to clear the navigation stack without using finish()? Thanks! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Scrolling text (marquee) in an AppWidget
Just thought I would post my solution, if anyone else wants to know. I had to add android:focusableInTouchMode=true in order to get it to work. I also might have added android:duplicateParentState=true to get it to work, but I'm not sure if that's necessary. Now that I got it working, though, I would not recommend trying this. It will not work reliably, as your widget will have to be focused in order for it to scroll. As soon as the user clicks somewhere to make it lose focus, or uses the trackball, the text no longer scrolls. We decided on a different approach, and I would recommend anyone else thinking that they have to have scrolling text in a widget to do the same. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: What is a WeakReference?
On Jul 23, 2:37 am, Indicator Veritatis mej1...@yahoo.com wrote: You left out something very important: the code hidden under // reload the image must not assume that it is not itself interrupted by yet another call to the garbage collector. That is, instead of simply continuing to use the soft/weak reference, it should make a strong reference to the same object, allowing this latter reference to either go out of scope or be set to null when it is done. You are referring to the code that Joseph Earl wrote above. That code snippet is NOT a proper way to use weak references; that cache should be using soft references. On the other hand, in the example blog post referred to by the OP, which uses weak references, that IS a proper way to use weak references. The main Activity already has a strong reference to the objects. The secondary thread does not need to create a strong reference; in fact, that would make the weak reference useless. But if we are making this strong reference, what was the point of using the weak/soft reference in the first place? Ah, that is the tricky thing about using them. Depending on when you can make and release the strong reference, they might not buy you much; they might not buy you anything at all. That is why they are not recommended for much outside of caches and normalized mappings. You are referring to a soft reference, not a weak reference. Soft references are good for caches. Weak references are definitely recommended for the idea given in the article, where the main thread has a strong reference, and the background thread has a weak reference. That way if the main thread is killed (i.e. the app is finished), if the background thread is still running then it won't prevent the weakly referenced objects from being destroyed. I also hate to throw this bit of information into the mix, but it should be known that Android will kill your process, and hence background threads anyways, when all your main threads have been destroyed (i.e. all your activities are finished, and there aren't any services running). This means that, even if you did have a background thread running, it would be killed, implying that weak references wouldn't help because everything is going to get killed anyways. That being said, there are still circumstances where the weak references matter: just because one activity is finished, doesn't mean all of your app's activities are necessarily finished. So it would be good if you went from your main activity into another sub-activity which began a download. But then the user presses back, because they don't want to bother waiting on the download. In that case your main activity is still alive, but the background thread is working on the sub-activity that was already finished. If that background thread had weak references, then that background thread would no longer be holding on to the resources of the sub-activity with strong references, and the system could GC those resources already, before the background thread dies. -Matt -Matt -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: To display the soft keyboard during the launch itself
You might get it to work if you request the focus for EditText on creation. Either add editText.requestFocus() in your onCreate(), or add a requestFocus/ tag inside the EditText's XML layout. EditText requestFocus/ /EditText -Matt On Jul 23, 4:52 am, harshe hars...@gmail.com wrote: no it didnot work :( am working in android sdk 2.2 my manifest is ?xml version=1.0 encoding=utf-8? manifest xmlns:android=http://schemas.android.com/apk/res/android; package=com.android.keyboard android:versionCode=1 android:versionName=1.0 application android:icon=@drawable/icon android:label=@string/ app_name activity android:name=.sample android:label=@string/app_name android:windowSoftInputMode=stateAlwaysVisible intent-filter action android:name=android.intent.action.MAIN / category android:name=android.intent.category.LAUNCHER / /intent-filter /activity /application /manifest please help me .. Thanks Harshe On Jul 23, 5:51 am, Matt matthew.quig...@gmail.com wrote: http://developer.android.com/guide/topics/manifest/activity-element.h... On Jul 22, 8:54 am, harshe hars...@gmail.com wrote: i have an activity with few edit text views and a button. TheSoft Keyboardis visible when I click the edit text view. But i want the softkeyboardto be visible during the launch itself , without clicking the edit text itself i must get thesoftkeyboardon the screen. Can anyone plzzz help me out in this -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en