¡@

Home 

2014/10/16 ¤W¤È 08:24:36

android Programming Glossary: something

Saving Activity state in Android

http://stackoverflow.com/questions/151777/saving-activity-state-in-android

how I navigate away from the app. I'm sure it's probably something simple like overriding onPause or something like that but I've.. it's probably something simple like overriding onPause or something like that but I've been poking away in the docs for 30 minutes..

Quitting an application - is that frowned upon?

http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon

can quit the app when he she decides to do so. That is not something that should be relied upon the OS to do. The application I am..

How to check visibility of software keyboard in Android?

http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android

if more than 100 pixels its probably a keyboard... ... do something here Easy ORIGINAL ANSWER Yes it's possible but it's far harder.. that can detect when the soft keyboard is shown and hidden something Android can't tell you weirdly . public class LinearLayoutThatDetectsSoftKeyboard..

How to programatically take a screenshot on Android?

http://stackoverflow.com/questions/2661536/how-to-programatically-take-a-screenshot-on-android

share improve this question I just recently did something similar to use for sharing with social media. Here is the code.. block e.printStackTrace Then when you need to access use something like this Uri uri Uri.fromFile new File mPath share improve..

How to call SOAP web service in Android

http://stackoverflow.com/questions/297586/how-to-call-soap-web-service-in-android

sort of SOAP library. You can either write your own or use something like kSOAP 2 . As you note others have been able to compile..

Download a file with Android, and showing the progress in a ProgressDialog

http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog

and post results to the UI with easily. If you are doing something like that in your app it could be really useful. 3. Use DownloadManager.. Once you are sure DownloadManager is available you can do something like this String url url you want to download DownloadManager.Request..

Android: How to declare global variables?

http://stackoverflow.com/questions/708012/android-how-to-declare-global-variables

have noted this is not a solution for persistent state something I perhaps should have emphasized more in the original answer... in favor of Singleton patterns. Somatik also pointed out something of this nature earlier although I didn't see it at the time... link above. Diane continues ...just likely to be something you regret in the future as you find your Application object..

When to call activity context OR application context?

http://stackoverflow.com/questions/7298731/when-to-call-activity-context-or-application-context

getApplicationContext when you know you need a Context for something that may live longer than any other likely Context you have.. Scenarios include Use getApplicationContext if you need something tied to a Context that itself will have global scope. I use.. leaks if the Context from getApplicationContext holds onto something created by your calls on it that you don't clean up. With an..

How to make an Android Spinner with initial text “Select One”

http://stackoverflow.com/questions/867518/how-to-make-an-android-spinner-with-initial-text-select-one

it is by no means guaranteed. Normally I wouldn't condone something like this but this question has been asked enough times and..

Android - basic gesture detection

http://stackoverflow.com/questions/937313/android-basic-gesture-detection

. It seems infinitely more complicated to implement something that recognizes a fling. I presume this is because it may span..

ActionBarSherlock - How to set the padding of each actionbar's icon?

http://stackoverflow.com/questions/10759282/actionbarsherlock-how-to-set-the-padding-of-each-actionbars-icon

ActionBarSherlock closer or further away from each other Something like android layout_marginLeft or android paddingRight If I..

Rotating a bitmap using JNI & NDK

http://stackoverflow.com/questions/14398670/rotating-a-bitmap-using-jni-ndk

weirder but the size doesn't match what I've set to it. Something is really weird here. Maybe I don't read put the data correctly..

Android : Check whether the phone is dual SIM

http://stackoverflow.com/questions/14517338/android-check-whether-the-phone-is-dual-sim

see both IMEI numbers. By some way get those two numbers. Something like screen capturing and image parsing for text. If anyone..

Android: ProgressDialog.show() crashes with getApplicationContext

http://stackoverflow.com/questions/1561803/android-progressdialog-show-crashes-with-getapplicationcontext

and starts anything else you needed eg. network IO . Something like this @Override public void onCreate Bundle savedInstanceState..

Android: ListView elements with multiple clickable buttons

http://stackoverflow.com/questions/1709166/android-listview-elements-with-multiple-clickable-buttons

in the list contains a TextView and two different Buttons. Something like this ListView Text Button 1 Button 2 Text Button 1 Button..

How to create directory automatically on SD card

http://stackoverflow.com/questions/2130932/how-to-create-directory-automatically-on-sd-card

it's mkdirs method to build all the needed directories. Something like create a File object for the parent directory File wallpaperDirectory.. Level 4 1.6 you'll also have to request the permission. Something like this in the manifest should work uses permission android..

Remove all debug logging calls before publishing: are there tools to do this?

http://stackoverflow.com/questions/2446248/remove-all-debug-logging-calls-before-publishing-are-there-tools-to-do-this

potentially tricky for instance if condition Log.d LOG_TAG Something data.load data.show If I comment the Log line then the condition..

Disable scrolling in webview?

http://stackoverflow.com/questions/2527899/disable-scrolling-in-webview

only and now I have decided to give Android a whirl. Something I haven't been able to figure out on Android is how to programmatically.. is how to programmatically prevent scrolling in a WebView Something similar to iPhones prevention of the onTouchMove event would..

Android, sending XML via HTTP POST (SOAP)

http://stackoverflow.com/questions/2559948/android-sending-xml-via-http-post-soap

type as text xml Set this entity in the SOAP request. Something like HttpPost httppost new HttpPost SERVICE_EPR StringEntity..

On logout, clear Activity history stack, preventing “back” button from opening logged-in-only Activites

http://stackoverflow.com/questions/3007998/on-logout-clear-activity-history-stack-preventing-back-button-from-opening-l

and install a BroadcastReceiver in all your Actvities. Something like this on your logout method Intent broadcastIntent new Intent..

Make a link in the Android browser start up my app?

http://stackoverflow.com/questions/3469908/make-a-link-in-the-android-browser-start-up-my-app

what you'll need to do is define your own scheme. Something along the lines of intent filter data android scheme anton action..

Can't create handler inside thread that has not called Looper.prepare()

http://stackoverflow.com/questions/3875184/cant-create-handler-inside-thread-that-has-not-called-looper-prepare

it This is the code Toast toast Toast.makeText mContext Something Toast.LENGTH_SHORT This is the exception java.lang.RuntimeException..

How do I retrieve the logged in Google account on android phones?

http://stackoverflow.com/questions/4038333/how-do-i-retrieve-the-logged-in-google-account-on-android-phones

any way to do it android share improve this question Something like this should work AccountManager manager AccountManager..

Android: Want to set custom fonts for whole application not runtime

http://stackoverflow.com/questions/4395309/android-want-to-set-custom-fonts-for-whole-application-not-runtime

to update it each time you add a new item to a layout. Something like below public void setLayoutFont Typeface tf Typeface.createFromAsset..

how to customize listview row android

http://stackoverflow.com/questions/4407865/how-to-customize-listview-row-android

your list item XML layout to any kind of View Layout... Something like this MyAdapter.java public class MyAdapter extends BaseAdapter..

How to open or simulate a click on an android Preference, created with XML, programatically?

http://stackoverflow.com/questions/4805896/how-to-open-or-simulate-a-click-on-an-android-preference-created-with-xml-prog

calls the protected showDialog method of ListPreference. Something like public void show showDialog null This way you won't run..

Percentage width in a RelativeLayout

http://stackoverflow.com/questions/4961355/percentage-width-in-a-relativelayout

give a percentage width to the host and port EditText's . Something like 80 for the host 20 for the port. Is this possible The following..

How to dismiss the dialog with click on outside of the dialog?

http://stackoverflow.com/questions/8384067/how-to-dismiss-the-dialog-with-click-on-outside-of-the-dialog

will close the dialog if you touch outside of the dialog. Something like Dialog dialog new Dialog context dialog.setCanceledOnTouchOutside..

android asynctask sending callbacks to ui

http://stackoverflow.com/questions/9963691/android-asynctask-sending-callbacks-to-ui

values caller.sometextfield.setText bla Something like this android android asynctask share improve this question..

Saving Activity state in Android

http://stackoverflow.com/questions/151777/saving-activity-state-in-android

case but it always gives me the first message no matter how I navigate away from the app. I'm sure it's probably something simple like overriding onPause or something like that but I've been poking away in the docs for 30 minutes or so and haven't.. message no matter how I navigate away from the app. I'm sure it's probably something simple like overriding onPause or something like that but I've been poking away in the docs for 30 minutes or so and haven't found anything obvious so would appreciate..

Quitting an application - is that frowned upon?

http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon

write an app that functions as a normal app that the user can quit the app when he she decides to do so. That is not something that should be relied upon the OS to do. The application I am trying to create is not an application for the Android Market...

How to check visibility of software keyboard in Android?

http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android

.getHeight activityRootView.getHeight if heightDiff 100 if more than 100 pixels its probably a keyboard... ... do something here Easy ORIGINAL ANSWER Yes it's possible but it's far harder than it ought to be. If I need to care about when the keyboard.. a variant of LinearLayout that can detect when the soft keyboard is shown and hidden something Android can't tell you weirdly . public class LinearLayoutThatDetectsSoftKeyboard extends LinearLayout public LinearLayoutThatDetectsSoftKeyboard..

How to programatically take a screenshot on Android?

http://stackoverflow.com/questions/2661536/how-to-programatically-take-a-screenshot-on-android

phone screen not by any program but from code. android screenshot share improve this question I just recently did something similar to use for sharing with social media. Here is the code that allowed my screen shot to be stored on sd card and used..

How to call SOAP web service in Android

http://stackoverflow.com/questions/297586/how-to-call-soap-web-service-in-android

share improve this question Android does not provide any sort of SOAP library. You can either write your own or use something like kSOAP 2 . As you note others have been able to compile and use kSOAP2 in their own projects but I haven't had to. Google..

Download a file with Android, and showing the progress in a ProgressDialog

http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog

to make calls to external REST apis in a background service and post results to the UI with easily. If you are doing something like that in your app it could be really useful. 3. Use DownloadManager class GingerBread and newer only This method is.. Exception e return false Method's name explains it all. Once you are sure DownloadManager is available you can do something like this String url url you want to download DownloadManager.Request request new DownloadManager.Request Uri.parse url..

Android: How to declare global variables?

http://stackoverflow.com/questions/708012/android-how-to-declare-global-variables

in this post for maximum visibility. ADDENDUM As some people have noted this is not a solution for persistent state something I perhaps should have emphasized more in the original answer. I.e. this is not meant to be a solution for saving user or.. in which use of Application subclasses is discouraged in favor of Singleton patterns. Somatik also pointed out something of this nature earlier although I didn't see it at the time. Because of Reto and Diane's roles in maintaining the Android.. of state. For a list of the differences see the Singleton explanation link above. Diane continues ...just likely to be something you regret in the future as you find your Application object becoming this big tangled mess of what should be independent..

When to call activity context OR application context?

http://stackoverflow.com/questions/7298731/when-to-call-activity-context-or-application-context

or getBaseContext to get a Context object. You only use getApplicationContext when you know you need a Context for something that may live longer than any other likely Context you have at your disposal. Scenarios include Use getApplicationContext.. than any other likely Context you have at your disposal. Scenarios include Use getApplicationContext if you need something tied to a Context that itself will have global scope. I use getApplicationContext for example in WakefulIntentService for.. will fail mostly related to the GUI . It can create memory leaks if the Context from getApplicationContext holds onto something created by your calls on it that you don't clean up. With an Activity if it holds onto something once the Activity gets..

How to make an Android Spinner with initial text “Select One”

http://stackoverflow.com/questions/867518/how-to-make-an-android-spinner-with-initial-text-select-one

work in future OS updates. It seems likely that it will but it is by no means guaranteed. Normally I wouldn't condone something like this but this question has been asked enough times and it seems like a reasonable enough request that I thought I would..

Android - basic gesture detection

http://stackoverflow.com/questions/937313/android-basic-gesture-detection

add to be the main activity which implements View.OnClickListener . It seems infinitely more complicated to implement something that recognizes a fling. I presume this is because it may span views If my activity implements OnGestureListener I don't..

ActionBarSherlock - How to set the padding of each actionbar's icon?

http://stackoverflow.com/questions/10759282/actionbarsherlock-how-to-set-the-padding-of-each-actionbars-icon

icon How can I make the icons of the actionbar using ActionBarSherlock closer or further away from each other Something like android layout_marginLeft or android paddingRight If I just add the icons on the actionbar they are further away compare..

Rotating a bitmap using JNI & NDK

http://stackoverflow.com/questions/14398670/rotating-a-bitmap-using-jni-ndk

in of what I get So as you can see not only the colors became weirder but the size doesn't match what I've set to it. Something is really weird here. Maybe I don't read put the data correctly Of course this is just an example. The code should work..

Android : Check whether the phone is dual SIM

http://stackoverflow.com/questions/14517338/android-check-whether-the-phone-is-dual-sim

broadcast event handling. By dialing 06# you will get to see both IMEI numbers. By some way get those two numbers. Something like screen capturing and image parsing for text. If anyone can think of some other ways they are most welcome. I would..

Android: ProgressDialog.show() crashes with getApplicationContext

http://stackoverflow.com/questions/1561803/android-progressdialog-show-crashes-with-getapplicationcontext

for me but you'll need to tinker that opens your ProgressDialog and starts anything else you needed eg. network IO . Something like this @Override public void onCreate Bundle savedInstanceState do all your other stuff here new Handler .postDelayed..

Android: ListView elements with multiple clickable buttons

http://stackoverflow.com/questions/1709166/android-listview-elements-with-multiple-clickable-buttons

clickable buttons I've a ListView where every element in the list contains a TextView and two different Buttons. Something like this ListView Text Button 1 Button 2 Text Button 1 Button 2 ... and so on ... With this code I can create an OnItemClickListener..

How to create directory automatically on SD card

http://stackoverflow.com/questions/2130932/how-to-create-directory-automatically-on-sd-card

a File object that wraps the top level directory you can call it's mkdirs method to build all the needed directories. Something like create a File object for the parent directory File wallpaperDirectory new File sdcard Wallpaper have the object build.. actually there as the SD Card may be removed. UPDATE Since API Level 4 1.6 you'll also have to request the permission. Something like this in the manifest should work uses permission android name android.permission.WRITE_EXTERNAL_STORAGE share improve..

Remove all debug logging calls before publishing: are there tools to do this?

http://stackoverflow.com/questions/2446248/remove-all-debug-logging-calls-before-publishing-are-there-tools-to-do-this

every time I release. Additionally removing a Log line is potentially tricky for instance if condition Log.d LOG_TAG Something data.load data.show If I comment the Log line then the condition applies to the next line and chances are load is not called...

Disable scrolling in webview?

http://stackoverflow.com/questions/2527899/disable-scrolling-in-webview

scrolling in webview Until now I have been an iPhone developer only and now I have decided to give Android a whirl. Something I haven't been able to figure out on Android is how to programmatically prevent scrolling in a WebView Something similar.. Something I haven't been able to figure out on Android is how to programmatically prevent scrolling in a WebView Something similar to iPhones prevention of the onTouchMove event would be great android scrolling webview share improve this question..

Android, sending XML via HTTP POST (SOAP)

http://stackoverflow.com/questions/2559948/android-sending-xml-via-http-post-soap

request. Wrap this string in a StringEntity and set its content type as text xml Set this entity in the SOAP request. Something like HttpPost httppost new HttpPost SERVICE_EPR StringEntity se new StringEntity SOAPRequestXML HTTP.UTF_8 se.setContentType..

On logout, clear Activity history stack, preventing “back” button from opening logged-in-only Activites

http://stackoverflow.com/questions/3007998/on-logout-clear-activity-history-stack-preventing-back-button-from-opening-l

stay under a logged in status. So you can use the sendBroadcast and install a BroadcastReceiver in all your Actvities. Something like this on your logout method Intent broadcastIntent new Intent broadcastIntent.setAction com.package.ACTION_LOGOUT sendBroadcast..

Make a link in the Android browser start up my app?

http://stackoverflow.com/questions/3469908/make-a-link-in-the-android-browser-start-up-my-app

take a look at the documentation for the data sub element. Basically what you'll need to do is define your own scheme. Something along the lines of intent filter data android scheme anton action android name android.intent.action.VIEW category android..

Can't create handler inside thread that has not called Looper.prepare()

http://stackoverflow.com/questions/3875184/cant-create-handler-inside-thread-that-has-not-called-looper-prepare

What does the following exception mean how can I fix it This is the code Toast toast Toast.makeText mContext Something Toast.LENGTH_SHORT This is the exception java.lang.RuntimeException Can't create handler inside thread that has not called..

How do I retrieve the logged in Google account on android phones?

http://stackoverflow.com/questions/4038333/how-do-i-retrieve-the-logged-in-google-account-on-android-phones

Google email account if they are already logged in. Is there any way to do it android share improve this question Something like this should work AccountManager manager AccountManager getSystemService ACCOUNT_SERVICE Account list manager.getAccounts..

Android: Want to set custom fonts for whole application not runtime

http://stackoverflow.com/questions/4395309/android-want-to-set-custom-fonts-for-whole-application-not-runtime

typeface once then runs setTypeface for each. You'd just have to update it each time you add a new item to a layout. Something like below public void setLayoutFont Typeface tf Typeface.createFromAsset getBaseContext .getAssets fonts BPreplay.otf TextView..

how to customize listview row android

http://stackoverflow.com/questions/4407865/how-to-customize-listview-row-android

you are not restricted to TextViews anymore you can change your list item XML layout to any kind of View Layout... Something like this MyAdapter.java public class MyAdapter extends BaseAdapter private LayoutInflater inflater private ArrayList String..

How to open or simulate a click on an android Preference, created with XML, programatically?

http://stackoverflow.com/questions/4805896/how-to-open-or-simulate-a-click-on-an-android-preference-created-with-xml-prog

create your dialog then included your own public method that calls the protected showDialog method of ListPreference. Something like public void show showDialog null This way you won't run into the issue of getOrder not working when there are PreferenceGroups..

Percentage width in a RelativeLayout

http://stackoverflow.com/questions/4961355/percentage-width-in-a-relativelayout

had to specify android layout_width 172dp I'd really like to give a percentage width to the host and port EditText's . Something like 80 for the host 20 for the port. Is this possible The following XML works on my Droid but it doesn't seem to work for..

How to dismiss the dialog with click on outside of the dialog?

http://stackoverflow.com/questions/8384067/how-to-dismiss-the-dialog-with-click-on-outside-of-the-dialog

You can use dialog.setCanceledOnTouchOutside true which will close the dialog if you touch outside of the dialog. Something like Dialog dialog new Dialog context dialog.setCanceledOnTouchOutside true Or if your Dialog in non model then 1 Set the..

android asynctask sending callbacks to ui

http://stackoverflow.com/questions/9963691/android-asynctask-sending-callbacks-to-ui

protected void onProgressUpdate Integer... values super.onProgressUpdate values caller.sometextfield.setText bla Something like this android android asynctask share improve this question You can create interface pass it to AsyncTask in constructor..