How to optimize your android app's performance

SDK Version: 
M3

So here's how you can optimize, analyze your current application using TraceView.
Open your Project, and after onCreate(), or anywhere you want to start Log tracing, paste the following lines:

  1. /* start tracing to "/sdcard/filename.trace" */
  2. Debug.startMethodTracing("filename");

It is very important to stop tracing after you have done debugging. To do that, place these lines before onCreate().
  1. public void onDestroy() {
  2.         // stop tracing
  3.         Debug.stopMethodTracing();
  4.     }

Now run your Project, do anything you'd like to optimize, and quit. Open up DDMS File Explorer, and download /sdcard/filename.trace to your hard disk drive.

Go to your Android SDK folder, open Tools directory, and run ./traceview filename.trace

Here's how it looks like:

Hello Baby – Baby birth calculator widget released

We have released a new widget on the Android Marketplace. Feel free to download it and don't forget to rate. Hello Baby is a free application, for those mothers / fathers / grandfathers / uncles, who are expecting a baby. The widget counts down to a given birth date, once entered.

Mastering Android Widget Development - Part3

SDK Version: 
M3

I just come to a new discovery regarding widgets. I was developing an appwidget, which - just like the widgets we are trying to make in this series of tutorials - and tried it out multiple phones. Unfortunatelly on one of our test phones it didn't function properly. For random intervals it stopped to refresh, and it din't responded to button presses on the widget, only after 1-2 minutes. After hard work I discivered the following:

Buttons on appwiget can have their onclick flunctionality thorough RemoteViews.setOnClickPendingIntent(). This method gets a PendingIntent ap parametes to bound to a button. PendingIntent's can have 3 types created with

getActivity(Context, int, Intent, int)


getBroadcast(Context, int, Intent, int)


and getService(Context, int, Intent, int).

How to use custom designed numbers in your android widget

SDK Version: 
M3
If you don't want to download external fonts into your application, this article will be useful to you. You can draw your own numbers for example in gimp from 0 to 9. Copy thoose numbers in to your project folder's res/drawable subfolder. Each number is a new png (for example: one.png, two.png...). Then don't forget to refresh this directory in eclipse.

In my last project I wrote an easy method, what I used to draw single numbers on a widget.

How to add external 3D fonts to your Android applications

SDK Version: 
M3
Step 1.
First, go to google.com, and find an eye-candy font, that you like the most. Look for „free 3d fonts”. I'm going to use this one: http://www.urbanfonts.com/fonts/Xtrusion.htm
After you have downloaded it, unzip if it is zipped.

Step 2.
Go to your project's location, open the „assets” folder, and create a new folder called „fonts”.
Copy and Paste your „xy.ttf” font to this new directory.

Step 3.
If you are using Eclipse, don't forget to refresh your project's directory tree, make sure your SDK can see your font file.

  1. /* Setting up fonts */
  2. Typeface fontFace = Typeface.createFromAsset(getAssets(), "fonts/xtrusion.ttf");
  3. Typeface fontFace2 = Typeface.createFromAsset(getAssets(), "fonts/other.ttf");
  4. TextView someText = (TextView)findViewById(R.id.TextView01);

Mastering Android Widget Development - Part2

SDK Version: 
M3

In Mastering Android Widget Development - Part1 we have gone trough the basics of appwidgets. Now we start to develop the example application, which couts time left to a given date.

First implement the configuration activity. It will contain a DatePicker, an OK button and a Cancel button, defined in the configuration.xml layout:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.   xmlns:android="http://schemas.android.com/apk/res/android"
  4.   android:layout_width="wrap_content"
  5.   android:layout_height="wrap_content"
  6.   android:orientation="vertical">
  7.         <DatePicker android:layout_width="wrap_content"
  8.         android:layout_height="wrap_content"
  9.         android:id="@+id/DatePicker">
  10.         </DatePicker>
  11.        
  12.         <LinearLayout
  13.         android:id="@+id/LinearLayout01"
  14.         android:layout_width="wrap_content"
  15.         android:layout_height="wrap_content"
  16.         android:orientation="horizontal">
  17.        

How to configure widget-settings by clicking on widget developer tutorial

SDK Version: 
M3

Sometimes you need to change your widget settings after you put one to home screen. In my new tutorial I will show an easy way to solve this problem.

ProgressBar updating using Message Handler

SDK Version: 
M3

You're going to learn how to make a progressbar, which gives you a feedback what's going on in the background.

Let say you have a LoadingScreen activity (loadingscreen.xml layout), and a Main activity (main.xml).

You'd like to do some job in the Main activity, and update the progressbar status at the same time. To do this, we are going to use Messages. Although, you can update you're progressbar by sending the progressbar instance itself to your Main activity, but that's obviously not the prettiest solution.

What we going to do is:

1. Declaring a progressbar instance in LoadingScreen Activity:

So in your LoadingScreen.java, after Oncreate(), you should add something like this line to your codeline: (don't forget to add a progressbar to your layout first!)

  1.   ProgressBar pb = (ProgressBar)findViewById(R.id.ProgressBar01);

2. Setting up a Handler to handle Messages from outside:

Mastering Android Widget Development - Part1

SDK Version: 
M3

In Days to Xmas tutorial you can see a simple widget example, which demonstrates what widgets are used for, and shows an example how they can work. Now I begin a series of tutorials to fully explain the working of widgets.
We will also create a sample application, during the tutorials, which will show a countdown to a given date in secunds, but things that are not required for this specific example applications will be explained too.

For this first part I will go though mainly the parts described in http://developer.android.com/guide/topics/appwidgets/index.html but I try to give more explanation and advice.

Some general thoughts at first:

How to download file/image from url to your device

SDK Version: 
M3

We wrote a code for download image from a website to the phone. You can work with images (and files) in your applications, but this article may be useful for java developers too.

Syndicate content