[android-beginners] Re: JSON help
Hey Sagar, I tried using it But i am facing a problem in it. I have a class say class abc { public String id; public String ver; } class pqr { public String lmn; public String xyz; } class holder { public Object [] params; } public void method() { abc aobj = new abc(1,a); pqr pobj = new pqr(a,b); gson = new Gson(); jsonstr = gson.toJson(pobj); Log.i(Output is ,+jsonstr); holder hold = new holder(); hold.params = new Object[2]; hold.params[0] = aobj; hold.params[1] = pobj; gson = new Gson(); jsonstr = gson.toJson(hold); Log.i(Output is ,+jsonstr); } Output {lmn:a,xyz:b} {params:[{},{}]} So if i have a user defined object as a ref of another object, it doesnt serialise it i suppose. If i do gson = new Gson(); jsonstr = gson.toJson(hold.params[0]); It gives the output perfectly.So its getting assigned I have posted this question on Gson forum but with no response. I hope someone knows the answer. I tried using Xstream but its giving me some exceptions while running the program. In Xstream they hv mentioned that Json object cannot hold references so i think it must be the same problem with Gson. Sorry for posting too much on Json, but i want an urgent solution. Has anyone succesfully tried using ang good Json library on android , if yes please gc me directions on it. Thanks in adv. Alok. On Fri, Sep 11, 2009 at 9:45 AM, sagar sagar.india...@gmail.com wrote: Hi Alok, Use Gson.. It is a google library for converting gson response directly to the class objects. Just google it and use.. On Sep 9, 11:51 pm, Alok Kulkarni kulsu...@gmail.com wrote: Thanks mark for your quick response. Regarding the get and put methods , i am using them currently . But it would hv been great if i could read the entire response in an object like the third party support .. Anyways nothing comes easily. I will have a look at the Jettison driver and post the solution when i have it. Thanks and Regards, Alok. On Wed, Sep 9, 2009 at 10:01 PM, Mark Murphy mmur...@commonsware.com wrote: Alok wrote: Some way to put the myClassObj in JSONObject and send it to server. JSON works with arrays and objects (roughly a HashMap), not custom classes. So, if you want to put stuff in a JSONObject, you have to do it yourself via put() method calls. On retreival i should be able to assign JSONObject to MyClass object and all values such as code , message should be automatically retrievable Use get() on the JSONObject. I have seen some dot net examples whering serialization / deserialization has been done to objects . How can i do it here? This has nothing to do with Android and everything to do with the JSON.org third-party library integrated in by Android. A quick Google search for: java jsonobject turned up: http://java-x.blogspot.com/2007/04/using-json-from-java.html http://stackoverflow.com/questions/944285/how-to-create-a-json-object. .. -- Mark Murphy (a Commons Guy) http://commonsware.com|http://twitter.com/commonsguy _The Busy Coders' Guide to *Advanced* Android Development_ In Print! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Call to activity problem
ok i tried it like u said but it crashing here it is how i tried please check n tell me how to correct it class someactivity extends extends Activity { *public* *void* onCreate(Bundle savedInstanceState) { //... call(); } public void call() { SmsReceiver *b* =*new* SmsReceiver(getBaseContext()); // or i tried SmsReceiver *b* =*new* SmsReceiver(getApplicationContext()) } } // now in class SmsReceiver * public* *class* SmsReceiver *extends* BroadcastReceiver { *static* Context *mContext*=*null*; *public* SmsReceiver(Context baseContext) { *mContext* = baseContext; } @Override *public* *void* onReceive(Context context, Intent intent) { //. Intent i = *new* Intent(*mContext*, neww.*class*); i.setFlags(Intent.*FLAG_ACTIVITY_NEW_TASK*); //startActivity(i); cant be used directally so used Activity nn = new Activity(); nn.startActivity(i); //or context.startActivity(i); } } but application crashesh as soon as it receives the sms.so please guys help me sort out this.thank you On Wed, Sep 9, 2009 at 11:12 PM, Roman ( T-Mobile USA) roman.baumgaert...@t-mobile.com wrote: --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Call to activity problem
kapnk...@gmail.com wrote: ok i tried it like u said but it crashing here it is how i tried please check n tell me how to correct it class someactivity extends extends Activity { *public* *void* onCreate(Bundle savedInstanceState) { //... call(); } public void call() { SmsReceiver _b_ = *new* SmsReceiver(getBaseContext()); // or i tried SmsReceiver _b_ =*new* SmsReceiver(getApplicationContext()) } } // now in class SmsReceiver * public * *class* SmsReceiver *extends* BroadcastReceiver { *static* Context /mContext/=*null*; *public* SmsReceiver(Context baseContext) { /mContext/ = baseContext; } @Override *public* *void* onReceive(Context context, Intent intent) { //. Intent i = *new* Intent(/mContext/, neww.*class*); i.setFlags(Intent. /FLAG_ACTIVITY_NEW_TASK/); //startActivity(i); cant be used directally so used Activity nn = new Activity(); nn.startActivity(i); //or context.startActivity(i); } } but application crashesh as soon as it receives the sms.so please guys help me sort out this.thank you Look at your Java stack trace for the exception (via adb logcat, DDMS, or the DDMS perspective in Eclipse), and it will probably indicate where things are going wrong. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 Available! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] listview scroll position
I have a listview and when i select an item a new activity is started, but when i go back the listview's scroll is positioned at the beginning the list. How can i save the scroll position and when i go back to the listview the scroll to be positioned in the same place. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: listview scroll position
Sorry for the post my mistake i just reload every time the view in onResume :) On Fri, Sep 11, 2009 at 2:45 PM, manigault manig...@gmail.com wrote: I have a listview and when i select an item a new activity is started, but when i go back the listview's scroll is positioned at the beginning the list. How can i save the scroll position and when i go back to the listview the scroll to be positioned in the same place. -- When I raise my flashing sword, and my hand takes hold on judgment, I will take vengeance upon mine enemies, and I will repay those who haze me. Oh, Lord, raise me to Thy right hand and count me among Thy saints. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: a problem about listview
Hi!you have a method in listvie class:setCachedColor or something like this.. Hope this will help you.. On Sep 8, 2009 9:43 AM, whitech whit...@163.com wrote: Hi all~ I've met this problem: while scrolling, the background of a listview change to black but not the background color which I'd define. How can I let the background color not change when scrolling? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] XML Digital Signatures API in Android
Hi, Will Android add Java APIs of JAVA 1.6 related to XML Digital Signatures in the upcoming versions of Android ? Is there any other APIs in Android for validating XML Digital Signatures ? Regards, Vinay H V --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] WebView opens a browser
Hello, My app has a webview.It opens a web browser when it receives 303 http response. I would like to make it display the new location page. I tried some WebSettings values,but I couldn't find any way. Does anybody have idea? Thank you. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] how to import packages in android?
Hai, In my application in need to use the java.image.io package, but it is not suppoted by android. Is there any way i can import packages into android. Please help me. I need to do the image processing in my app, which can be done through image.io. If it is not really possible please let me know. It would be helpful for me. Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: how to import packages in android?
If you have a jar package or the source code you can always add a dependency to the project settings. When you open the properties of your project and check the Java build path you can add libraries or Java Projects as additional dependency. -- Roman Baumgaertner Sr. SW Engineer-OSDC ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Sep 11, 6:39 am, mmkr manutd...@gmail.com wrote: Hai, In my application in need to use the java.image.io package, but it is not suppoted by android. Is there any way i can import packages into android. Please help me. I need to do the image processing in my app, which can be done through image.io. If it is not really possible please let me know. It would be helpful for me. Thanks in advance. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] findViewById bug or documentation problem
Here is a tip on how to use generated layout id's. If your layout has id=@+id/foobarid -- THIS IS WRONG this will NOT work with findViewById method. You have to do it this way android:id=@+id/foogarid -- CORRECT In both cases, the build will generate R.id.foobarid, but findViewById (R.id.foobarid) will not find it unless you use the android: namespace in the layout file. That seems to be inconsistent and should be considered an Android bug because it is really, really hard to discover what is wrong. In addition the SDK documentation actually shows the WRONG way to do it. So at the very least that is a bug in the documentation. ERROR IN DOCUMENTATION - see http://developer.android.com/guide/topics/resources/available-resources.html --- quote -- When declaring an ID value for an XML tag, use this syntax. Example: TextView id=@+id/nameTextbox/, and refer to it this way in Java: findViewById(R.id.nameTextbox) -- end quote -- The above example is WRONG. It should be this way -- TextView android:id=@+id/nameTextbox/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: findViewById bug or documentation problem
jotobjects wrote: ERROR IN DOCUMENTATION - see http://developer.android.com/guide/topics/resources/available-resources.html --- quote -- When declaring an ID value for an XML tag, use this syntax. Example: TextView id=@+id/nameTextbox/, and refer to it this way in Java: findViewById(R.id.nameTextbox) -- end quote -- The above example is WRONG. It should be this way -- TextView android:id=@+id/nameTextbox/ Way back in the spring of 2008, you did not need the android: prefix on android:id. They changed that, but apparently missed this reference in the documentation. Most of the documentation is correct, AFAICT. You may wish to post this to http://b.android.com if it is not already there. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Training in Germany, 18-22 January 2010: http://bignerdranch.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: findViewById bug or documentation problem
Looks like the page has some id attribute with the proper namespace prefix and some that are missing it. I've filed a bug internally to make sure this gets fixed. thanks! Xav On Fri, Sep 11, 2009 at 9:08 AM, Mark Murphy mmur...@commonsware.com wrote: jotobjects wrote: ERROR IN DOCUMENTATION - see http://developer.android.com/guide/topics/resources/available-resources.html --- quote -- When declaring an ID value for an XML tag, use this syntax. Example: TextView id=@+id/nameTextbox/, and refer to it this way in Java: findViewById(R.id.nameTextbox) -- end quote -- The above example is WRONG. It should be this way -- TextView android:id=@+id/nameTextbox/ Way back in the spring of 2008, you did not need the android: prefix on android:id. They changed that, but apparently missed this reference in the documentation. Most of the documentation is correct, AFAICT. You may wish to post this to http://b.android.com if it is not already there. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Training in Germany, 18-22 January 2010: http://bignerdranch.com -- Xavier Ducrohet Android Developer Tools Engineer Google Inc. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: confusion about bluetooth
How about USB? Can we access USB from Java? -jim On Aug 24, 2:02 pm, gymshoe gyms...@bresnan.net wrote: Ah. Thank you. On Aug 24, 12:58 pm, Mark Murphy mmur...@commonsware.com wrote: The current Android release offers: StereoBluetoothsupport (A2DP and AVCRP profiles) (http://developer.android.com/sdk/android-1.5-highlights.html) However, it has also been stated in the developers forum: There is noBluetoothAPI in the SDK at this time. http://groups.google.com/group/android-developers/browse_thread/threa... So how are theBluetoothA2DP or AVCRP profiles used if there are no BluetoothAPI's? There are noBluetoothAPIs available in the SDK for Java applications. Applications and features built into the firmware have access to bluez. -- Mark Murphy (a Commons Guy)http://commonsware.com Android App Developer Books:http://commonsware.com/books.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: preventing Activity from destroying
There are other ways to make a Service always work even if the phone sleeps; it depends on what your Service does. For example, if the Service's job is to respond to an Activity, then it is awake when the Activity is awake. Or if it responds to a broadcast Intent, ditto. Generally speaking, a Service that keeps the phone awake all the time to run like a daemon will eat up the battery, but there are cases where that's necessary. Why does your Service need to stay awake? Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Sep 10, 10:15 pm, Jason shivi...@gmail.com wrote: John Yes, you are right. Pressing Home does call just onStop; while pressing Back calls onDestroy. Btw, how do you ensure that the service keeps running and doing its job even when the phone goes to sleep (power save mode)? I added PowerManager = pm = (PowerManager) getSystemService(Context.POWER_SERVICE); WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MyService); wl.acquire(); but it didn't seem to help On Wed, Sep 9, 2009 at 8:26 PM, John P. johnny.d.p...@gmail.com wrote: It is true that when the Back button is pressed, onDestroy() is called. But hitting the Home button invokes the activity's onStop() for me. Now, it is true that if Android determines it needs memory, it may then invoke onDestroy() on the stopped activity. It sounds like if you want your activity to do something while minimized (i.e. in the background with no user interaction), then this logic should really be in your service. I wrote a program where a service continuously does some processing while keeping its state. I have an activity that binds to the service, gets the state, and appropriately rehydrates its own state accordingly. Everytime the activity pauses, it unbinds. Everytime it resumes, it rebinds. All the continuous processing is done on the service, and the activity gives the user a chance to modify the data. But when the activity is dead, the service continues on until I explicitly kill it through the said activity. On Sep 9, 10:01 pm, Jason shivi...@gmail.com wrote: How do I achieve the effect of 'minimizing' a UI activity? I have a UI activity that gets destroyed each time I click the Home, phone etc. keys on the phone. I would like the UI activity to be sent to the background; since it is bound to a service and processing the data returned by the service continuously. Clicking on the app ends up calling onCreate, onStart again. I would like to restart (onResume) instead. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: preventing Activity from destroying
The service is picking up GPS locations; and sending to the server. Hence it needs to stay awake -- the server is tracking locations of the user on the web. On Fri, Sep 11, 2009 at 2:30 PM, Yusuf Saib (T-Mobile USA) yusuf.s...@t-mobile.com wrote: There are other ways to make a Service always work even if the phone sleeps; it depends on what your Service does. For example, if the Service's job is to respond to an Activity, then it is awake when the Activity is awake. Or if it responds to a broadcast Intent, ditto. Generally speaking, a Service that keeps the phone awake all the time to run like a daemon will eat up the battery, but there are cases where that's necessary. Why does your Service need to stay awake? Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Sep 10, 10:15 pm, Jason shivi...@gmail.com wrote: John Yes, you are right. Pressing Home does call just onStop; while pressing Back calls onDestroy. Btw, how do you ensure that the service keeps running and doing its job even when the phone goes to sleep (power save mode)? I added PowerManager = pm = (PowerManager) getSystemService(Context.POWER_SERVICE); WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MyService); wl.acquire(); but it didn't seem to help On Wed, Sep 9, 2009 at 8:26 PM, John P. johnny.d.p...@gmail.com wrote: It is true that when the Back button is pressed, onDestroy() is called. But hitting the Home button invokes the activity's onStop() for me. Now, it is true that if Android determines it needs memory, it may then invoke onDestroy() on the stopped activity. It sounds like if you want your activity to do something while minimized (i.e. in the background with no user interaction), then this logic should really be in your service. I wrote a program where a service continuously does some processing while keeping its state. I have an activity that binds to the service, gets the state, and appropriately rehydrates its own state accordingly. Everytime the activity pauses, it unbinds. Everytime it resumes, it rebinds. All the continuous processing is done on the service, and the activity gives the user a chance to modify the data. But when the activity is dead, the service continues on until I explicitly kill it through the said activity. On Sep 9, 10:01 pm, Jason shivi...@gmail.com wrote: How do I achieve the effect of 'minimizing' a UI activity? I have a UI activity that gets destroyed each time I click the Home, phone etc. keys on the phone. I would like the UI activity to be sent to the background; since it is bound to a service and processing the data returned by the service continuously. Clicking on the app ends up calling onCreate, onStart again. I would like to restart (onResume) instead. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Adroid on a phone with Windows OS
There is a cross-compiler for Android-iPhone, and there is of course the Android emulator on WinXP. But the best way to run Android on WinMo without a virtual machine would be to implement the Android low- level API in WinMo. Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Sep 10, 10:01 am, Chris Stratton cs07...@gmail.com wrote: On Sep 9, 4:30 pm, Earl Wilson earl...@gmail.com wrote: No you can not. The type of applications you can develop on a windows mobile device is windows mobile applications. Android is different the windows. That is the same as trying to run or develop Mac OSX apps for your windows phone. What keeps you from developing OSX applications for windows is not primarily something technical, but Apple's perhaps over-reaching claims of control over the OSX api's. In the case of android, the apis are not only documented but the actual code is available (and if you are careful to do it right, legal) to use as the basis of a translation layer. In other words, for running android apps on a windows mobile phone the problems are simply technical... if someone wants to do it badly enough, they will come up with a way to. More practical and popular approaches seem to be to try to get a build of android running entirely in place of windows mobile. The HTC line of android phones at least give the impression of being descended from from the hardware of their windows mobile platforms. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Security framework available on android??
BouncyCastle is also included in Android, if you're looking for encryption. Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Sep 10, 10:01 am, Jack Ha jack...@t-mobile.com wrote: Assuming this is what you are looking for: http://developer.android.com/guide/topics/security/security.html -- Jack Ha Open Source Development Center ・T・ ・ ・Mobile・ stick together The coverage you need at the price you want The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Sep 9, 9:46 pm, Sudeep Jha sudeep.neti...@gmail.com wrote: Which security framework is available or can be ported to android ? Warm Regards, Sudeep --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: preventing Activity from destroying
Jason wrote: The service is picking up GPS locations; and sending to the server. Hence it needs to stay awake -- the server is tracking locations of the user on the web. Keeping the service alive all the time is very bad for the battery. I provide an analysis of this here: http://groups.google.com/group/android-developers/msg/36bf61dfb78ef4cc In your case, it will be substantially worse, as you are keeping the GPS radio on all the time. If a G1 lasts 8 hours in that state, I'd be impressed. I also cover the fallacy of keeping services alive all the time in a recent blog post: http://www.androidguys.com/2009/09/09/diamonds-are-forever-services-are-not/ -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Need Android talent? Ask on HADO! http://wiki.andmob.org/hado --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] onSaveInstanceState question
When is onSaveInstanceState called and how can I use the save variables in the bundle? In my experiment, this is what I observed: When the application is running is foreground, pressing the Home key resulted in: onSaveInstanceState onPause onStop Clicking the application icon again (i.e. bring it back to foreground) resulted in: onRestart onStart onResume With the application now in the foreground, pressing the Back key resulted in: onPause onStop onDestroy Note the onSaveInstanceState is NOT getting called when Back key is pressed. How does one then save and restore the application state when the Back key is pressed and then the application is brought to foreground? Clicking the application icon again (i.e. bring it back to foreground) resulted in: onCreate LocationActivity onStart LocationActivity onResume The Bundle value in onCreate is null (perhaps because onSaveInstanceState was not called when Back was clicked. And onRestoreInstanceState was never called either. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: onSaveInstanceState question
jason wrote: How does one then save and restore the application state when the Back key is pressed and then the application is brought to foreground? When the BACK button is pressed, the currently-running activity is destroyed, not put in the background. If you wish to save something when the activity is being destroyed, implement onDestroy() and save it. Where you save it (flat file, SharedPreferences, database, the Internet) is up to you. Bear in mind that onDestroy() may also be called in the case of a screen rotation or other configuration change, since, by default, the current activity is destroyed and started in that case. The Bundle value in onCreate is null (perhaps because onSaveInstanceState was not called when Back was clicked. More accurately, the Bundle is null because the application is starting from scratch. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Training in Germany, 18-22 January 2010: http://bignerdranch.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: onSaveInstanceState question
You are so right!! 2009/9/11 Mark Murphy mmur...@commonsware.com jason wrote: How does one then save and restore the application state when the Back key is pressed and then the application is brought to foreground? When the BACK button is pressed, the currently-running activity is destroyed, not put in the background. If you wish to save something when the activity is being destroyed, implement onDestroy() and save it. Where you save it (flat file, SharedPreferences, database, the Internet) is up to you. Bear in mind that onDestroy() may also be called in the case of a screen rotation or other configuration change, since, by default, the current activity is destroyed and started in that case. The Bundle value in onCreate is null (perhaps because onSaveInstanceState was not called when Back was clicked. More accurately, the Bundle is null because the application is starting from scratch. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Training in Germany, 18-22 January 2010: http://bignerdranch.com -- Atte [[Jose Luis Ayerdis Espinoza]] http://blognecronet.blogspot.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: onSaveInstanceState question
Mark Murphy wrote: If you wish to save something when the activity is being destroyed, implement onDestroy() and save it. Where you save it (flat file, SharedPreferences, database, the Internet) is up to you. Bear in mind that onDestroy() may also be called in the case of a screen rotation or other configuration change, since, by default, the current activity is destroyed and started in that case. Actually, I should point out that more common places to save this sort of stuff are onPause() and onStop(), since your process may be terminated by Android to rapidly free memory without onDestroy() being called. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Training in Germany, 18-22 January 2010: http://bignerdranch.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: onSaveInstanceState question
Thanks, Mark. Hmm, pressing the Back key so easily kills the activity. Is there a way to trap Back key within an application and prevent/control this behavior? For sub-activity screens, does the Back key have the same behavior (killing the app/activity) or does it go back to the parent activity in the stack? On Sep 11, 4:58 pm, Mark Murphy mmur...@commonsware.com wrote: Mark Murphy wrote: If you wish to save something when the activity is being destroyed, implement onDestroy() and save it. Where you save it (flat file, SharedPreferences, database, the Internet) is up to you. Bear in mind that onDestroy() may also be called in the case of a screen rotation or other configuration change, since, by default, the current activity is destroyed and started in that case. Actually, I should point out that more common places to save this sort of stuff are onPause() and onStop(), since your process may be terminated by Android to rapidly free memory without onDestroy() being called. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android Training in Germany, 18-22 January 2010:http://bignerdranch.com --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: onSaveInstanceState question
jason wrote: Is there a way to trap Back key within an application and prevent/control this behavior? Implement onKeyDown() in your activity and watch for KeyEvent.KEYCODE_BACK. Please bear in mind that your users will get irritated if you make it difficult for them to navigate your application, so make sure if you override the BACK button, it is for a good reason, not just because you do not like the BACK button. For example, with the built-in Browser application, the BACK button is used for going back in the browsing history. While this is fairly natural, I still get frustrated at times because I try to use the BACK button to exit the Browser and merely go back a page. When the vast majority of apps use the BACK button to exit the current activity, it is sometimes difficult for users to adjust to applications that choose to handle this differently. Or, possibly, I'm just a moron. For sub-activity screens, does the Back key have the same behavior (killing the app/activity) or does it go back to the parent activity in the stack? If you are referring to activities started by one of your activities via startActivity(), then, yes, the BACK button behaves the same. The BACK button's job is to destroy the current activity and return control to the previous activity on the stack. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Development Wiki: http://wiki.andmob.org --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: onSaveInstanceState question
Thanks, Mark. That was helpful. If you are referring to activities started by one of your activities via startActivity(), then, yes, the BACK button behaves the same. The BACK button's job is to destroy the current activity and return control to the previous activity on the stack. Is there a way for an (sub-)activity to pass values to the previous activity on the stack (when Back key is pressed) without resorting to persistence storage or static varables in the app? On Sep 11, 5:20 pm, Mark Murphy mmur...@commonsware.com wrote: jason wrote: Is there a way to trap Back key within an application and prevent/control this behavior? Implement onKeyDown() in your activity and watch for KeyEvent.KEYCODE_BACK. Please bear in mind that your users will get irritated if you make it difficult for them to navigate your application, so make sure if you override the BACK button, it is for a good reason, not just because you do not like the BACK button. For example, with the built-in Browser application, the BACK button is used for going back in the browsing history. While this is fairly natural, I still get frustrated at times because I try to use the BACK button to exit the Browser and merely go back a page. When the vast majority of apps use the BACK button to exit the current activity, it is sometimes difficult for users to adjust to applications that choose to handle this differently. Or, possibly, I'm just a moron. For sub-activity screens, does the Back key have the same behavior (killing the app/activity) or does it go back to the parent activity in the stack? If you are referring to activities started by one of your activities via startActivity(), then, yes, the BACK button behaves the same. The BACK button's job is to destroy the current activity and return control to the previous activity on the stack. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android Development Wiki:http://wiki.andmob.org --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: onSaveInstanceState question
jason wrote: Is there a way for an (sub-)activity to pass values to the previous activity on the stack (when Back key is pressed) without resorting to persistence storage or static varables in the app? Use startActivityForResult() rather than startActivity() to start it, use setResult() to set the result, and use onActivityResult() to retrieve the result. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Development Wiki: http://wiki.andmob.org --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: confusion about bluetooth
Nope, there is nothing available on Java level. You could try to write some JNI wrapper to access the interfaces on native level (look in extern/bluez folder). -- Roman Baumgaertner Sr. SW Engineer-OSDC ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Sep 11, 2:17 pm, cellurl gpscru...@gmail.com wrote: How about USB? Can we access USB from Java? -jim On Aug 24, 2:02 pm, gymshoe gyms...@bresnan.net wrote: Ah. Thank you. On Aug 24, 12:58 pm, Mark Murphy mmur...@commonsware.com wrote: The current Android release offers: StereoBluetoothsupport (A2DP and AVCRP profiles) (http://developer.android.com/sdk/android-1.5-highlights.html) However, it has also been stated in the developers forum: There is noBluetoothAPI in the SDK at this time. http://groups.google.com/group/android-developers/browse_thread/threa... So how are theBluetoothA2DP or AVCRP profiles used if there are no BluetoothAPI's? There are noBluetoothAPIs available in the SDK for Java applications. Applications and features built into the firmware have access to bluez. -- Mark Murphy (a Commons Guy)http://commonsware.com Android App Developer Books:http://commonsware.com/books.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Finishing all the running activities?
Hi, I want to completely exit my application under test in my test code (ActivityInstrumentationTestCase) before launching each test. Since there is no exit in an android app. Is there a way I can traverse through all the activities of an app so that I call Finish() on each i.e. finish all the activities that have been started. Thanks Yasser --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Resizing ImageView
I have to say creating layouts in Android would have to be the most frustrating experience in all my years of programming. I dread it every time I create a new Android app. I simply want to have four images laid out horizontally across the screen. All four images are the same size and have the same width + height. The images are quite large because I want them to still look good if they are used on an Android device with a high res. It would be fine if I could just set the size of the imageview in the XML but because it is never known how big the screen res will be I cant really hard code a value in if I always want the four pics to be sized evenly across the screen. So is the approach to just create four imageviews in something like a horizontal linear layout and then changing the size of the imageview in the code? If so I cant seem to find anywhere how to change the size of an imageview dynamically? Am I better off physically creating the imageviews at runtime so I can set the size to be 1/4 the screen size? Any help would be greatly appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: Resizing ImageView
You should be able to do this as follows: setMinimumWidth(w); setMaxWidth(w); setMinimumHeight(h); setMaxHeight(h); Or, if you set it up as a horizontal linear layout that contains the four different views and give each view the same weight (e.g. give each ImageView a weight value of 1), then the layout should be able to do the resizing work for you and make sure that each view takes up the same amount of space on the screen, regardless of the screen size or resolution. Personally, I think that creating layouts in android with XML files is genius. It takes some getting used to, but once you get the hang of it, it is very handy. Thanks, -- There are only 10 types of people in the world... Those who know binary and those who don't. -- On Fri, Sep 11, 2009 at 8:33 PM, BGH bradleygh...@gmail.com wrote: I have to say creating layouts in Android would have to be the most frustrating experience in all my years of programming. I dread it every time I create a new Android app. I simply want to have four images laid out horizontally across the screen. All four images are the same size and have the same width + height. The images are quite large because I want them to still look good if they are used on an Android device with a high res. It would be fine if I could just set the size of the imageview in the XML but because it is never known how big the screen res will be I cant really hard code a value in if I always want the four pics to be sized evenly across the screen. So is the approach to just create four imageviews in something like a horizontal linear layout and then changing the size of the imageview in the code? If so I cant seem to find anywhere how to change the size of an imageview dynamically? Am I better off physically creating the imageviews at runtime so I can set the size to be 1/4 the screen size? Any help would be greatly appreciated. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---