performance

Mojito builder

SDK Version: 
M3

Last week, in spite of the winter the weather was very mild. The beams of the winter sun brought forward the memories of the summer: hot weather, girls in bikinis, mojitos! We have already gotten a promise for the first two in a certain form here in Helloandroid HQ (the heating system will be repaired, and we 'll have some women colleagues), but it is our task to make coctails.

  1. public class Mojito {
  2.         private final int mWhiteRum;    //cl
  3.         private final int mBrownSugar;  //spoun
  4.         private final int mLime;                //clove
  5.         private final int mMenta;               //piece
  6.         private final int mSoda;                //decilitre
  7.                
  8.         public Mojito(int whiteRum, int brownSugar, int lime, int menta, int soda){
  9.                 mWhiteRum = whiteRum;
  10.                 mBrownSugar = brownSugar;
  11.                 mLime = lime;
  12.                 mMenta = menta;
  13.                 mSoda = soda;
  14.         }
  15. }

Quick guide to quick autocomplete textview

SDK Version: 
M3

This demo shows how to speed up the original autocomplete textview assuming that we can work with ordered data.

Let's prepare a simple test environment, which demostrate the difference between the two versions. Then let's generate a few thousand test data, and create two textviews from which we will speed up the second one.

  1. public class Main extends Activity {
  2.         AutoCompleteTextView mAutoCompleteTextViewOriginal;
  3.         AutoCompleteTextView mAutoCompleteTextViewQuick;
  4.  
  5.         @Override
  6.         public void onCreate(Bundle savedInstanceState) {
  7.                 super.onCreate(savedInstanceState);
  8.                 setContentView(R.layout.main);
  9.                
  10.                 String[] values =  createLongSortedStringArray(4);
  11.        
  12.                 mAutoCompleteTextViewOriginal = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextViewOriginal);
  13.                 ArrayAdapter<String> originalAdapter = new ArrayAdapter<String>(this, R.layout.autocomplete_listitem, values);
  14.                 mAutoCompleteTextViewOriginal.setAdapter(originalAdapter);

Motorola Milestone CPU Overclock

SDK Version: 
M3

Use at your own risk!

milestone

OMAP3 processors used by the device are available. In this example,Milestone, Milestone 2, Droid, Droid 2 Global, Droid X, A853/A854. Other devices run this processor on higher frequencies, some even run it on 1,2 ghz.

The first step root. Superoneclick, it can be done in 5 minutes. 2.2.2 is no problem with it can be given to root. Click

The second step is to install overclock milestone.
Download: Click

Open Milestone Overclock and press the Load module. Set the slider to how you want to run.I recommend the 1GHz and stable.

How to build with Android NDK

SDK Version: 
M3
The Android NDK is a companion tool to the Android SDK that lets you build performance-critical portions of your apps in native code. If you write native code, your applications are still packaged into an .apk file and they still run inside of a virtual machine on the device. The fundamental Android application model does not change.
First thing to do:
Go to http://developer.android.com/sdk/ndk/index.html and download Android NDK.
Okay, now you unzip the downloaded NDK zip to your hard disk drive.

If you are a windows user, you also have to have Cygwin, go to http://www.cygwin.com/ and download the latest version.
Install it, and run it, you should see a "linux-like" console.

Removing an app icon from launcher

SDK Version: 
M3


Creating an application that does not appear among the launchable applications with an icon is easy.
Just do not put a launcher activity into AndroidManifest.xml

  1. <intent-filter>
  2.   <action android:name="android.intent.action.MAIN" />
  3.   <category android:name="android.intent.category.LAUNCHER" />
  4. </intent-filter>

Removing an application icon after installation programatically is a bit more tricky.
You can not disable the icon itself, but you can disable one component of an application. So disabling the applications launcher activity will result its icon to be removed from launcher.

The code to do this is simple:

  1. ComponentName componentToDisable =
  2.   new ComponentName("com.helloandroid.apptodisable",
  3.   "com.helloandroid.apptodisable.LauncherActivity");
  4.  
  5. getPackageManager().setComponentEnabledSetting(
  6.   componentToDisable,

Communicating between an activity and the browser - callback

SDK Version: 
M3

A few days ago Gabor made an article about communicating between activites. I'm currently working on a pet project that uses Oauth with the google data api, where I had to get a response from the browser, so let's take a look at communicating between an activity and a browser.

Communicating between running activities

SDK Version: 
M3

Starting a new activity from another and passing some data to it is a simple and basic thing in android. But if you want an already running activity to come to foreground, and pass data to it, it can be a bit tricky.

First of all by default if you call an activity with an intent, a new istance of that activity will be created and displayed, even if another instance is already running. To avoid this the activity must be flagged that, it should not be instantiated multiple times. To achieve this we will set the launchMode of the activity to singleTask in the AndroidManifest.xml

  1. <activity android:name="Activity1" android:launchMode="singleTask" android:label="@string/app_name">

This way when we call this activity using an intent, if there is an existing instance, the system will route the request to it. Hoever the onCreate method, where we usually process the passed extraData, will not run this time.

Reading logs programatically

SDK Version: 
M3

Writing logs into logcat from yuor application is quite easy, reading the logcat programmatically is just a bit more tricky.
Reading logs is usually used for bugreport purposes.

logcat

Checking users installed flash version

SDK Version: 
M3

Here is a little tutorial on checking users flash version. It comes in handy, if you want to use flash content in your app. Flash lite can cause some problems, so this snippet is also about that...

How to use static variables in activities

SDK Version: 
M3

As previously described in Leaving an Android application, when you exit an app by pressing back button its resources are not completely destroyed immediately.

I would like to explain a concrete mistake I met multiple times, in connection with this behavior, which is easy to commit, if you forget this.

Syndicate content