Wallpaper tutorial - Part 2

SDK Version: 
M3

This article was requested by some of our community members. It is based on the Android Gallery, ImageView Example tutorial by Sasikumar (Part 1 is here). I extended his example with a new function. If you long click on the big image, an alert dialog show up and ask “Do you want to use this image as a wallpaper?". If you click yes, the actually image will be your new wallpaper.

I only changed the Activity class:

  1. package org.androidpeople.gallery;
  2.  
  3. import java.io.IOException;
  4.  
  5. import android.app.Activity;
  6. import android.app.AlertDialog;
  7. import android.content.Context;
  8. import android.content.DialogInterface;
  9. import android.content.res.TypedArray;
  10. import android.graphics.Bitmap;

Speeding up android applications

SDK Version: 
M3

First of all, define what do we mean under "speed": in one hand its the time that the code needs to execute, on the other hand its the time the user needs to wait for the user interface. The two things can greatly differ, of course you must optimize the code performance, but the most important is what the user sees from it. Don't make the user wait, unless its necessary.

Do not pull back the ui thread
The very basic principle is to never run slow operations on the user interface thread! If you do this the interface will freeze until the operation is executed, which is not a nice user experience. If the execution takes too long the android system will detect it and offer the opportunity to the user to force close the frozen application:

Move your app update: we got our nexus one!

Last week, our award for 4th Place in the Move your app challange, a Nexus one has finally arrived. The shipping took 2 months, and we were surprised, that the phone came in without any damage.
nexus
I won't go into detail about unboxing, and reviewing all the little details, the gadget sites already tore the nexus one apart months ago anyway.
Lets take a look at it, from the developers point of view.

How to update custom listview images simply

SDK Version: 
M3
So in this tutorial I'm going to show you how to refresh imageviews' contents periodically (let say by Handlers if you download the picture from web).
I had painful 2 days figuring out what's a good solution here, I tried to give IDs to imageviews and that sort of sick things, but believe me, it wasn't worth it. The solution is so simply that I hardly can believe.
What we're lookign for here is instead of create new Adapters and HashMaps (which contains ListView data), we just update it's values, and Android will do the trick for us.
The most important thing is DO NOT AT ANY CIRCUMSTANCES CREATE A NEW ADAPTER (or a new data source that holds the Adapter's data).
There's an exception of course, you obviously have to create a new Adapter in OnCreate() { }.

Let me show you how it works:

How to set an image as wallpaper on different api levels

SDK Version: 
M3

Pretty easy! :)
Use the context’s setWallpaper method.

  1. getApplicationContext().setWallpaper(bitmap)

Don’t forget to add the SET_WALLPAPER permission to your AndroidManifest.xml!

  1. <uses-permission android:name="android.permission.SET_WALLPAPER" />

Differences between api versions
On Android 1.5 the wallpaper looks cool, doesn’t it? :) The backgroud fills the screen.

But on 1.6 and higher android strechs the wallpaper like this:

It’s not bad if you use high resolution wallpaper, but the low res wallpapers look crappy.

Leaving an Android application

SDK Version: 
M3
One of the strange things with android is that there is no "the user has closed the application" event. Applications activities often just go to the background, and the android system may kill them whenever it wants, even when another activity of the application is still running in the foreground.

You can not be sure that activities you started and sent to the background are sill there storing their state, and if you are just an android user, you can not be sure that applications that you left simply by pressing back button are completely destroyed.

To make it more complex, using intents it is even possible to start an activity of another application.

Native application or web application

Having an android device, makes sense mainly if you have Internet access all the time. So if we can suppose everyone access the net, it is obvious to think, that a mobile optimized site/web application can be used instead of a native application.

As I see the main advantage of a web based solution is platform independence, the same code can run on on any mobile phone .

I'd like to make an overview of the possibilities, and defects of a web based solution.

Possibilities:

It has been a while since is possible to create complex html and JavaScript based web applications for PC browsers. You can check out for example the YUI Library which helps building a rich user interface for such web applications.

Xml remote procedure calls on android

SDK Version: 
M3

Using web services on android phones, is pretty simple. For most popular services, there is a usable library available.
Here is a little snippet for using an android library, called android-xmlrpc.

Android developers are funny! :)

In the New Android 2.2 Froyo API: Log.wtf() has been added.
It stands for "What a terrible failure", what a coincidence... :)




By the way, has anyone tried the command ./adb lolcat instead of ./adb logcat?

How to make a phone call from your application

SDK Version: 
M3

To enable your application to initiate a phone call, you must set permissions in the manifest file:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3.       package="com.bubudsadasdas"
  4.       android:versionCode="1"
  5.       android:versionName="1.0">
  6.     <application android:icon="@drawable/icon" android:label="@string/app_name">
  7.         <activity android:name=".phonecalls"
  8.                   android:label="@string/app_name">
  9.             <intent-filter>
  10.                 <action android:name="android.intent.action.MAIN" />
  11.                 <category android:name="android.intent.category.LAUNCHER" />
  12.             </intent-filter>
  13.         </activity>
  14.  
  15.     </application>
  16.     <uses-sdk android:minSdkVersion="3" />
  17. <uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
  18. </manifest>

Now create a new activity with a call method. It should look like this:
 

Syndicate content