[android-beginners] Re: How do you determine screen orientation at startup?
try: int orientation = getWindowManager().getDefaultDisplay ().getOrientation(); //works in an Activity class then you can use the 4 constants to determine what the int means: Configuration.ORIENTATION_LANDSCAPE Configuration.ORIENTATION_PORTRAIT Configuration.ORIENTATION_SQUARE Configuration.ORIENTATION_UNDEFINED serge On Jun 28, 1:23 pm, Jason Van Anden jason.van.an...@gmail.com wrote: I would like to know what the screen orientation is when my app starts. Can someone please point me in the right direction? Thank You, j --~--~-~--~~~---~--~~ 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: String format of numbers into currency
short and sweet examples: http://www.java2s.com/Code/Java/I18N/JavaI18NFormatNumberFormat.htm serge On Jun 14, 7:17 pm, MMC2 m...@mmc2.com.au wrote: Further to my formatting problem and your reply, I changed s from being a string to being a double and it now works. Thanks for your help. I would still appreciate your recommendation on a writeup about string formatting and your thoughts on the sync connection problem described below. Mike - Original Message - From: MMC2 m...@mmc2.com.au To: android-beginners@googlegroups.com Sent: Sunday, June 14, 2009 3:28 PM Subject: [android-beginners] Re: String format of numbers into currency Thanks Mark for your reply, but when I include the line you suggested String t=customFormat($###,###.###, s); I don't get an error message but the app crashes at run time. I comment out the line and it runs ok. Can you help further please? On a separate issue. I frequently get a message unable to open sync connection when I try to run my app. I am using Eclipse. To get around it I restart my computer. I am using a laptop with approx 1.5Gig memory. Could you explain what the message means and would more memory help? Also could you recommend where I would find a good writeup on string formatting? Regards Mike - Original Message - From: Mark Murphy mmur...@commonsware.com To: android-beginners@googlegroups.com Sent: Saturday, June 13, 2009 7:52 AM Subject: [android-beginners] Re: String format of numbers into currency MMC2 wrote: I want to format a number that is held in a string called s to have a leading $ sign and two places after the decimal point. So partly following an example I wrote static public String customFormat(String pattern, String s ) { DecimalFormat myFormatter = new DecimalFormat(pattern); String stringformatoutput = myFormatter.format(s); return stringformatoutput; } then in my code where I went to use this I wrote customFormat($###,###.###, s); String t = stringformatoutput; hoping to have my formatted string ready for output in t, but I get an error message that stringformatoutput cannot be resolved. Can someone set me straight please String t=customFormat($###,###.###, s); -- 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] Re: Invokation Exception
As MrChaz wrote, you'll definitively need the Camera permission and for checking if you are still getting exceptions, try this: Camera cam = null; try{ cam = Camera.open(); }catch(Exception ex){ Log.e(Camera.open(),+ex); } if(cam==null){ return; } //it is very important that the camera be released by the app that opens it. try{//try-finally block to ensure that the camera is released try{ cam.startPreview(); }catch(Exception ex){ Log.e(Camera.startPreview(),+ex); return; } //other work here }finally{ try{ cam.release(); }catch(Exception ex){ Log.e(Camera. release(),+ex); } } serge On Jun 13, 9:51 am, MrChaz mrchazmob...@googlemail.com wrote: Have you added the Camera permission to the manifest? On Jun 12, 11:32 am, Urizev uri...@gmail.com wrote: I am developing an application which uses the camera of my G2. The code using the camera is showed below: Camera cam = Camera.open(); if (cam == null) { return; } cam.startPreview(); It throws and Exception and I do not know why. Someone has any idea? com.sun.jdi.InvocationException occurred invoking Regards --~--~-~--~~~---~--~~ 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: Differentiating between Simulator and Real device
Ashish, in the emulator, the DeviceID from the TelephonyManager is 000, i.e., 15 zeros. It is not that on a real device. try (in an Activity for example): TelephonyManager tm = (TelephonyManager) getSystemService (Context.TELEPHONY_SERVICE); // must have android.permission.READ_PHONE_STATE tm.getDeviceId(); serge On May 8, 1:43 am, aa aagarwa...@gmail.com wrote: Hi All, I need to change urls depending on simulator v/s. real device. Do anyone know how can I detect simulator v/s. a real device. Thanks, Ashish --~--~-~--~~~---~--~~ 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 hide alert dialog programmatically?
do yourAlert.hide(); all Dialog children have this method. serge On Apr 12, 6:35 pm, SteleFreak mijatovste...@gmail.com wrote: Is there a way to hide alert dialog after it has been shown, but programmatically?? Or is the BACK button only way? Or if i need to implement a button , what method should I call for alert to be hidden? --~--~-~--~~~---~--~~ 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: Cannot access Phone Number on HTC G1
Assuming that you are trying to read the phone number of a phone by using your app (and not the Settings app), here's an example to be used in an Activity class: TelephonyManager tm = (TelephonyManager)getSystemService (Context.TELEPHONY_SERVICE); // android.permission.READ_PHONE_STATE String phoneNumber = tm.getLine1Number(); serge On Mar 26, 8:28 pm, julius jul...@msa.co.nz wrote: Hi, I have an application which is trying to access the Phone Number. It has the Access rights to: android.permission.READ_PHONE_STATE and this works in the emulator, however, on my phone it doesn't seem to be able to access the number. When I go into: Home = Menu = Setting = About phone = Status third from the top is 'Phone number' however it has nothing below this text, that is there is no phone number listed. I suspect that this is obtained from the SIM card, but I could be wrong. Does anyone know where I might be able to configure this or where the number comes from? Note that if I call someone, my phone number turns up on his/her phone. Thanks for any help. Julius. --~--~-~--~~~---~--~~ 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: separating the decimal from the whole?
here's a slower but sometimes more precise way, e.g., if you're dealing with currency: double d = 124.50d; BigDecimal ii = new BigDecimal(+d); Log.d(whole and decimal,BigDecimal ii = +ii+ = new BigDecimal (\\+d); d = +d); Log.d(whole and decimal,whole = ii.intValue() = +ii.intValue ()); Log.d(whole and decimal,decimal = ii.remainder(BigDecimal.ONE) = +ii.remainder(BigDecimal.ONE)); extracts from the log: BigDecimal ii = 124.5 = new BigDecimal(+d); d = 124.5 whole = ii.intValue() = 124 decimal = ii.remainder(BigDecimal.ONE) = 0.5 sm1 On Mar 23, 3:28 pm, droozen droozenr...@gmail.com wrote: I'm a bit confused about your question. You ask a question and then pretty much answer it. :) There's other ways, as you say, but that's pretty much how you do it in java, too. x = 124.5 y = x - int(x) (so now y = 0.5 and x = 124.5) z = x - y (so z = 124.0 a = y * 3 ( a now = 1.5 ) b = z + a ( here's you're only error. 124 + 1.5 will give you b = 125.5, unless you are casting it to an int) Some other ways. String myX = Double.toString(x); (gives you x as a string) String s = myX.substring(myX.indexOf(.) + 1) (s = everything after the .) String r = myX.substring(0, myX.indexOf(.) (r = everything before the .) a = Double.parseDouble(s) * 3 (Turn everything after the . back into a double and multiply) b = Double.parseDouble(r) + a (And turn everything before the . back into a number and finish your calc Of course, using string manipulation like this you'll have to have a lot more checks for nulls and whatnot (what if there is no decimal part, converting it to a string might not yield a . in the string). Best way is as you posted, though. On Mar 20, 10:36 pm, Jintsubo jints...@gmail.com wrote: So I having a good crack at my first Android app, I've completed all the tutorials and suddenly realised I haven't a clue about how to do simple mathematics in Java. I have some (self taught) experience in PHP, Python etc, I'm no expert but I have managed to get the things done that I want to do. What I can do in Python but can't for the life of me figure out in javndroid; how to separate the decimal from the whole. for example, 124.50. I want to do some calcs using only the 0.50 and then when I'm finished, add it back onto the 124.0. x = 124.50 y = x - int(x) (there are other ways but for simplicity sake)... y = 0.50 z = x - y = 124.0 a = y * 3 = 1.5 b = z + a = 125.0 Any pointers greatly appreciated. JR --~--~-~--~~~---~--~~ 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: MODIFY_AUDIO_SETTINGS permission
i tried this permission in one of my apps and it ran fine, on an adp1. i seached the issues and found nothing; here http://code.google.com/p/android/issues/list there may be another problem in your app or what you're trying to do is not supported by the current version of android. it is currently quite limited in the audio functions accessible by apps. maybe someone else here knows about this, and if not then please post in the issues list. these get looked at by android/google staff, but you have to be patient, many issues don't get timely attention. the staff appear to be overworked these days. serge On Mar 18, 1:45 pm, Beth emez...@gmail.com wrote: Hello there, I first wrote to the android developer group about this and I got no responses. Has anybody successfully set the MODIFY_AUDIO_SETTINGS use permission? I try to set it and get a permission exception with every run of my application. Thanks for any insight you might have. Regards, Beth --~--~-~--~~~---~--~~ 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: MODIFY_AUDIO_SETTINGS permission
my app also uses-permission WRITE_SETTINGS. maybe you could add this one also and try. serge On Mar 21, 12:10 pm, sm1 sergemas...@gmail.com wrote: i tried this permission in one of my apps and it ran fine, on an adp1. i seached the issues and found nothing; herehttp://code.google.com/p/android/issues/list there may be another problem in your app or what you're trying to do is not supported by the current version of android. it is currently quite limited in the audio functions accessible by apps. maybe someone else here knows about this, and if not then please post in the issues list. these get looked at by android/google staff, but you have to be patient, many issues don't get timely attention. the staff appear to be overworked these days. serge On Mar 18, 1:45 pm, Beth emez...@gmail.com wrote: Hello there, I first wrote to the android developer group about this and I got no responses. Has anybody successfully set the MODIFY_AUDIO_SETTINGS use permission? I try to set it and get a permission exception with every run of my application. Thanks for any insight you might have. Regards, Beth --~--~-~--~~~---~--~~ 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 do I set the value of an EditText
i use myEditText.setText(hello, TextView.BufferType.EDITABLE); works fine serge On Mar 21, 5:55 am, Tseng tseng.priv...@googlemail.com wrote: An error message would be helpful Otherwise it's hard to help you, other than guessing what could be the reasons for it. Maybe you haven't set the ID correctly, using a wrong ID (which doesn't even exist in the XML Layout file) or you're using setContentView/setView after you have using findViewById. This could throw up a NullPointer Exception when you try to access (because findViewById returns 0 if no layout has been set or the View with this ID was not found). On Mar 20, 9:00 pm, Lovedumplingx lovedumpli...@gmail.com wrote: That's what I thought too but I crash the task every time the activity that contains this code is started: EditText userText = (EditText) findViewById(R.id.userText); userText.setText(userParam); This is the basic way I thought to have the value set but it crashes every time. On Mar 19, 10:53 pm, Isaac Waller ad...@isaacwaller.com wrote: A String _is_ a CharSequence. There is no need for a cast. On Mar 19, 3:35 pm, Will sem...@gmail.com wrote: Cast the String to a CharSequence. String x = foo; EditTextET; ET.setText((CharSequence) x); On Mar 19, 10:43 am, Lovedumplingx lovedumpli...@gmail.com wrote: Ok...so I've scoured and scoured and played and fiddled but I can't figure it out. I want to allow the user to set preferences for an application and I want the preferences to be displayed in theEditTextarea if/when they come back to change them again. In my head I'm thinking I would be able to use setText() but no...that takes a CharSequence and I have a string and don't know how to make a CharSequence (which according to what I've read is supposed to be a read-only thing anyway). So...does anyone know how to put text into anEditTextfield without relying on the XML? I really want to do this via application preferences. Thanks.- Hide quoted text - - Show quoted text - --~--~-~--~~~---~--~~ 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 read specific part in a string
Looks good guruk. It's quite fast. I timed it. fyi: The code I posted earlier can also work with input of xml tags with attributes, such as Hello, this is a test start attr1=\value1\12345/start ... which is common with tags, and it also avoids raising the nasty RuntimeException IndexOutOfBoundsException (by method substring) when a tag is not in the given string, which can happen in my apps. Exceptions such as these are normally not indicated by Eclipse Europa because, being RuntimeException children, they do not require a throws clause in the method signature when they are not caught by a try-catch in the method. These things often are what makes the difference between a 3-star and a 4-star rating. For handling absent tags without having to manage the exception downstream, I recommend the use of {if(xstart0)return ;} String x1tag = + xtag + ; String x2tag = / + xtag + ; int xstart = xhtml.indexOf(x1tag); if(xstart0)return ; int x1len = x1tag.length(); int xend = xhtml.indexOf(x2tag); if(xend0)return ; return xhtml.substring(xstart + x1len, xend); Or you could use a try-catch clause in the method if you know that the exception will not occur frequently and you don't want to do anything with the exception, and you want to keep going, such as: try{ String x1tag = + xtag + ; String x2tag = / + xtag + ; int xstart = xhtml.indexOf(x1tag); int x1len = x1tag.length(); int xend = xhtml.indexOf(x2tag); return xhtml.substring(xstart + x1len, xend); }catch(Throwable resume){ return ; } regards, serge On Mar 14, 2:38 pm, guruk ilovesi...@gmail.com wrote: Hi and thanks for all your great help So I also like to share what I use now public String TakeIt (String xtag, String xhtml) { String x1tag = + xtag + ; String x2tag = / + xtag + ; int xstart = xhtml.indexOf(x1tag); int x1len = x1tag.length(); int xend = xhtml.indexOf(x2tag); return xhtml.substring(xstart + x1len, xend); } And as Usual.. one Problem is solved, the next appear. Please if you know how to update a Gallery and also a Listview after a Thread answer here:http://groups.google.com/group/android-beginners/t/1bdc014cee0d317b Great People!! Thanks --~--~-~--~~~---~--~~ 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 read specific part in a string
Albert, I don't think that it can be done using StringTokenizer. serge On Mar 14, 12:17 pm, Albert Hernández albert.hernan...@gmail.com wrote: I think that the methods proposed here are very heavy: XML Parsing is too much for that easy task Check it manually is not optimal I suggest you to have a look on the class StringTokenizer:http://developer.android.com/reference/java/util/StringTokenizer.html Albert On Mar 13, 11:57 pm, sm1 sergemas...@gmail.com wrote: I do it this way (it works for me): /** * @param tag The tag without the angle bracket, i.e., * the given value does not start with lt;. * @param str The string containing the tags and data. * @return empty string when tag absent or str invalid. */ String takeit(String tag,String str){ try{ int i = str.indexOf(+tag+); if(i0){ i = str.indexOf(+tag+ ); } if(i0) { return ;//tag not found } String s = str.substring(i); i = s.indexOf(); if(i0) { //no matching end-angle-bracket () return ; } s = s.substring(i+1);//the returned string begins with the data of this tag int j = s.indexOf(/+tag+); //in this version, tag/ tags are not used. if(j0) { //TODO Log.d(...) return ; } s = s.substring(0,j); // j is the position of the end-tag. return s.trim(); }catch(Exception ex){ /* TODO maybe Log.d(myClass,ex+ - Thread.currentThread() +.takeit() returning empty string; + tag = +tag +; str = +str ); */ return ; } } cheers serge On Mar 12, 4:34 pm, EECOLOR eeco...@gmail.com wrote: I think that would be something like this: public String takeit(String str, String tag) { return str.replace(.*? + tag + (.*?)/ + tag + .*, $1); } Greetz Erik On Thu, Mar 12, 2009 at 7:14 PM, guruk ilovesi...@gmail.com wrote: Hi, i have a long String and need to capture some text in between of some tags. for example: myString=Hello, this is a test start12345/start and here i like to say markioioidddad/marki what is that opxmarknotwise/ opxmark and now i close; How would you do in java regex or any short thing like: starttag = takeit(myString,start); //result = 12345 marktag =takeit(myString,marki); //result = oioidddad opxmark=takeit(myString,opxmark); //result == notwise thanks a lot from your java newbie :) chris --~--~-~--~~~---~--~~ 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 read specific part in a string
I do it this way (it works for me): /** * @param tag The tag without the angle bracket, i.e., * the given value does not start with lt;. * @param str The string containing the tags and data. * @return empty string when tag absent or str invalid. */ String takeit(String tag,String str){ try{ int i = str.indexOf(+tag+); if(i0){ i = str.indexOf(+tag+ ); } if(i0) { return ;//tag not found } String s = str.substring(i); i = s.indexOf(); if(i0) { //no matching end-angle-bracket () return ; } s = s.substring(i+1);//the returned string begins with the data of this tag int j = s.indexOf(/+tag+); //in this version, tag/ tags are not used. if(j0) { //TODO Log.d(...) return ; } s = s.substring(0,j); // j is the position of the end-tag. return s.trim(); }catch(Exception ex){ /* TODO maybe Log.d(myClass,ex+ - Thread.currentThread() +.takeit() returning empty string; + tag = +tag +; str = +str ); */ return ; } } cheers serge On Mar 12, 4:34 pm, EECOLOR eeco...@gmail.com wrote: I think that would be something like this: public String takeit(String str, String tag) { return str.replace(.*? + tag + (.*?)/ + tag + .*, $1); } Greetz Erik On Thu, Mar 12, 2009 at 7:14 PM, guruk ilovesi...@gmail.com wrote: Hi, i have a long String and need to capture some text in between of some tags. for example: myString=Hello, this is a test start12345/start and here i like to say markioioidddad/marki what is that opxmarknotwise/ opxmark and now i close; How would you do in java regex or any short thing like: starttag = takeit(myString,start); //result = 12345 marktag =takeit(myString,marki); //result = oioidddad opxmark=takeit(myString,opxmark); //result == notwise thanks a lot from your java newbie :) chris --~--~-~--~~~---~--~~ 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: g1 developer firmware update
Merci Jean-Baptiste. On Mar 13, 5:36 pm, Jean-Baptiste Queru j...@android.com wrote: http://www.htc.com/www/support/android/adp.html JBQ On Fri, Mar 13, 2009 at 11:06 AM, Michael Bollmann michael.bollm...@googlemail.com wrote: this might be a stupid question... but ill ask anyway :) i received my g1 developer phone today when i run my software it warns me that i'm developing with sdk 1.1 and my phone runs 1.0 is there any official update source? (searching the net brought only some strange homebrew solutions) thanks in advance michael -- Jean-Baptiste M. JBQ Queru Android Engineer, Google. Questions sent directly to me that have no reason for being private will likely get ignored or forwarded to a public forum with no further warning. --~--~-~--~~~---~--~~ 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: Background Color
an example of what Mark had in mind, I think: EditText android:id=@+id/entry android:layout_width=fill_parent android:layout_height=wrap_content android:background=@android:drawable/editbox_background android:layout_below=@id/label/ also you could use Java code, such as in this example for a subclass of Dialog, such as an AlertDialog instance: getWindow().setBackgroundDrawable( new ColorDrawable (Color.DKGRAY) ); Note that the last technique is not guaranteed to be supported over the long term. Romain Guy from Google had a nice post recently on performance issues for backgrounds: http://android-developers.blogspot.com/2009/03/window-backgrounds-ui-speed.html serge On Mar 11, 1:26 pm, Mark Murphy mmur...@commonsware.com wrote: AJ wrote: I'm a complete newb here (got a Hello World app working, but otherwise my mind is a blank slate as far as Java goes), but how do you set the background color for an application that will utilize nothing but text and simple shapes? Put an android:background attribute on the appropriate elements of your layout XML. It can either be a simple color or a reference to a Drawable resource (e.g., PNG, gradient). -- Mark Murphy (a Commons Guy)http://commonsware.com _The Busy Coder's Guide to Android Development_ Version 2.0 Published! --~--~-~--~~~---~--~~ 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 format time in millis to human readable?
There may be built-in methods for such things as 5 minutes ago but I don't know any yet. for the current time in human-readable form, using some default date display format (which may or may not be dependent on user-preferred locale and date format selection, this remains TBD for Android), the fastest way is: +new Date() and with a given time in millis, it would be as in: Build.TIME +Build.TIME+ = +new Date(Build.TIME) Calendar is recommended for conversions (e.g., time zone changes) and for other calculations with dates, such add, after, before, compareTo. When you create a Calendar, it is already set to the current time: Calendar cal = Calendar.getInstance(); is usually equivalent and preferable to: long millis = System.currentTimeMillis(); //don't do these 4 statements Date date = new Date(millis); Calendar c = Calendar.getInstance(); c.setTime(date); And if you need to use SimpleDateFormat, because for example you don't want to use the default format you get from Date, then take special care because some implementations are not multithreaded, therefore unless you know for sure that Android's implementation is multithreaded, then don't cache the instance and use a local variable that only lives in the method, don't use a field. This makes SimpleDateFormat somewhat expansive to use but usually it is only used for some UI work (i.e., not background work), therefore using it may be OK for many apps. happy coding serge On Mar 8, 4:33 am, TAKEphONE shimo...@gmail.com wrote: Hi, Is there any internal method/object I can use to return a format like the built-in call log does ? (i.e. 5 minutes ago, 2 days ago...) On Mar 6, 2:55 pm, Tseng tseng.priv...@googlemail.com wrote: I wouldn't really use this method to be honest. Even the Android Documentation sugest to use native methods, instead of writing your own stuff for methods which are already available (i.e. simple date formating). [Use Native Methods]http://developer.android.com/guide/practices/design/performance.html#... On Mar 6, 1:20 pm, droozen droozenr...@gmail.com wrote: Sometimes I construct my human readable strings in a separate function by myself, mostly because I imagine it's faster. Something like. int iMonth = cal.get(Calendar.MONTH) + 1; // Months from the calendar are offset by one. Add one if you want human readable. int iDay = cal.get(Calendar.DAY_OF_MONTH); String month = Integer.toString(iMonth); if(iMonth 10){ month = 0 + month; // Otherwise, you might get something like 1/1/1900, instead of 01/01/1900 } String day = Integer.toString(iDay); if(iDay 10){ day = 0 + day; } String humanReadable = month + / + day + / cal.get(Calendar.YEAR); But really, you should be using SimpleDateFormat, I suppose... On Mar 6, 5:55 am, Łukasz Warchoł warchol...@gmail.com wrote: - Show quoted text - --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---