platform specials

Developing a clothing game for Android

SDK Version: 
M3
What the hell am I doing? Developing a clothing game for Android...

Last time I was really bored, i tried to make a simple clothing game for android.

Here is the tutorial:

Mastering Android Widget Development - Part4

SDK Version: 
M3

As described in the previous part, we will use a Service to update the appWidget.
So we will have the Service below, which gets the command (right now we have only the update command), ant the appwidgetId, reads the date from sharedPreferences and updates the widget.

  1. package com.helloandroid.countdownexample;
  2.  
  3. import java.util.Date;
  4.  
  5. import android.app.Service;
  6. import android.appwidget.AppWidgetManager;
  7. import android.content.Intent;
  8. import android.content.SharedPreferences;
  9. import android.os.IBinder;
  10. import android.widget.RemoteViews;
  11.  
  12. public class CountdownService extends Service {
  13.         // command strings to send to service
  14.         public static final String UPDATE = "update";
  15.  
  16.         @Override
  17.         public void onStart(Intent intent, int startId) {
  18.                 //a command, to define what to do, will be important only in the next tutorial part, now there is only update command
  19.                 String command = intent.getAction();
  20.                 int appWidgetId = intent.getExtras().getInt(

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:

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.

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.

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:

Debugging database

SDK Version: 
M3

When I first tried to manage an sqlite database on an android device I was not sure about where I fail in it. Can I even insert the records into the database, or I fail only to read the data from it? So I started to search for possibilities to debug the database lifecycle.

The system stores databases in the /data/data/package_name/databases folder by default.

In a command line using the adb (Android Debug Bridge - found in the android sdk tools library) you can access the databases on a running emulator like below:

  1. adb -s emulator-5554 shell
  2.  
  3. sqlite3 /data/data/package_name/databases/database_name

After this you can type normal SQL commands to test the content. For example:

  1. SELECT * FROM table_name;

This will list the table content (in an ugly format), or say that it does not exists.

Days to Xmas widget tutorial

SDK Version: 
M3

My second article based on Norbert Möhring's HelloWidget tutorial, but i think it's easier. :) It will look like this:


xmas widget

Syndicate content