Archive

Archive for April, 2010

Android Intents…

April 21, 2010 Leave a comment

Something came to my mind, I want to make a multi tab app where each tab will have its own activity.

I found out that Android have this TabHost, and we can put View inside each tab, but instead I want to spawn another activity on each tab.
So, the most basic is how to spawn an activity.
Throw the codes in Eclipse, like this:

Intent myIntent = new Intent(this, tabView.class);
startActivityForResult(myIntent , 0);

The above will spawn a tabView activity. So, I designed a homescreen which has a couple button, one of the button will launch this tabView activity, where the class of tabView is a generic activity that appear on every tab page, so how do we give extra data into each tab where there’s only 1 tabView activity for all tabs?
Luckily Android provide us with Extras. Modifying the above codes, like so:

Bundle bundle = new Bundle();
bundle.putString("page", page);
Intent myIntent = new Intent(this, tabView.class);
myIntent.putExtras(bundle);
startActivityForResult(myIntent, 0);

The above will add extra data to the target activity using Intent.

One step closer to finishing my app now…

Advertisements
Categories: Android

Android ListActivity…

April 21, 2010 Leave a comment

Alright, got some free time, grab a cup of coffee and digging out the XML UI of Android.

I want to make a scrollable list for Android, I happen to have a reason to dig this to put it on my app.
In Android there is this thing called Activity, from official Android, I know that it handle the UI part where the UI is serialized in a XML format.

For a single view, we can use a Activity derived class, but if we want to add a ListView automatically, Android has ListActivity that does most of the works for you, I just found this out just now.

OK, here’s the goal: I want to make a list of some items with icon on the left and text on the right so the user can tap on it. Unlike other framework like .NET where I can manually put those items directly to the List, but in Android they have this Adapter thing that connects your view to your model/data.

Today, I found out that using this Adapter I can automatically connect some items into the view.

Throw an eclipse IDE, and add the following codes in main.xml:

> LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
> ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
/>
> /LinearLayout>

notice the ListView widget above, has “@android:id/list”, for common id, I often see the use of “@+id/something” as the id, this change is needed for Android to find this particular list id. So, when the app is launched, it will look for the default name widget, this @android:id/list state that this list is a default one that Android can find to set it with ListActivity, so this one is automatically accessed by ListActivity, this particular id is important otherwise your app will crash, trust me I just proved it just now. 😀

OK, now throw some codes on the main activity as follows:

package com.azacode.FunList;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class FunList extends ListActivity {
/** Called when the activity is first created. */

String[] items = { "lorem", "ipsum", "dolor", "sit", "amet",
"consectetuer", "adipiscing", "elit", "morbi", "vel",
"ligula", "vitae", "arcu", "aliquet", "mollis",
"etiam", "vel", "erat", "placerat", "ante",
"porttitor", "sodales", "pellentesque", "augue",
"purus"};

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

setListAdapter(new ArrayAdapter(this, R.layout.row, R.id.label, items));
}
}

Now, take a look at the setListAdapter above, I instantiate a ArrayAdapter for this project, the reason is just to bind the strings inside items into the ListActivity’s list that we defined above. But, we have this R.layout.row and R.id.label, where does this come from? here is the codes for that, inside row.xml:


>?xml version="1.0" encoding="utf-8"?>
>LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>

>ImageView
android:id="@+id/icon"
android:layout_width="22px"
android:layout_height="wrap_content"
android:paddingLeft="2px"
android:paddingTop="2px"
android:paddingRight="2px"
android:paddingBottom="2px"
android:src="@drawable/icon"
/>

>TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="44sp"
/>

>/LinearLayout>

The above code only draw a icon on the left and text on the right, this layout will be used as a row view, so when Android draw each row of our list, this layout will be used for drawing each row.

So, simple call to new ArrayAdapter(this, R.layout.row, R.id.label, items) will bind the items into the listactivity listview and it will use the resource layout stored in R.layout.row, and the text stored in R.id.label.

I tend to forgot this simple matter, but this short text will help me remember…

Categories: Android

Android App Development

April 21, 2010 Leave a comment

Another free minutes to write, with my broken and aching knee, recently I’ve been fell off my bike, and got my knee injured pretty bad, but this won’t stop me from coding, phew I am just another hopeless software engineer.

Just got back home in Bandung and clear my Boss’s Quad Core PC dust in the corner of my room, and setup the Android SDK right away. Recently I’ve been interested with this Google Android Platform, and I think I’ll make 1 or 2 apps for this platform just for fun and perhaps profit?.

Been looking around on the net, and I see that Indosat already setup a online android market called i-store, but I haven’t tried it, anyway I don’t have Android phone, I am a poor engineer, if someone can hand me one? I think I can make this 2 apss faster in the device, hehe, who would want to give me a free android phone anyway. If I finished these 2 apps, I’ll try to pitch the apps to Android Market, well at least this local indonesia i-store android market.

I hope the new 2 apps will be finished sooner, if I have spare time, another learning time is needed since I don’t know much about Java, but I can grasp its general idea since I am working on .NET for my daily job.

Just wait and see…

Categories: Android

Android.. oh Android

April 18, 2010 2 comments

Hiya,

Happy just to have a couple minutes of my own to write something that made me interested for a couple days, yeap Android.

Seeing Android phones market in Indonesia is gaining more popularity by the Cellphone provider, so I think why not take a look at what it offer. Frankly speeking, I don’t like that much of Android, since I hate menu that not visible on the screen, I have to hit menu to show the menu, and I hate to use physical back button when you have a big touchscreen on the phone. Aside from it, I see that this platform going to be better in the future.

Enough the intro,

As of 3 days ago, I was trying to establish the development tools for Android in my MacBook, then I go to android website, download the sdk and install it, but what? no platform is installed, then I go to AVD manager inside it and download all platform for Mac and Windows, and download Eclipse using ADT, ok, I got it working now…

Eclair 2.1 running on my emulator, I can make a couple simple apps using Android Dalvik’s Java (Man, I don’t like Java, this is the first time ever I code in Java). Dalvik’s Garbage Collection really killing me, the hiccup I can’t stand it. The Emulator seems slow unlike iPhone SDK Emulator which is fast.

I can’t get myself to code the OpenGL, I want to code some simple OpenGL using C, just to find that no C is support on Android SDK? What? iPhone support C/C++, why don’t Android support C, then I look around and I saw Android Native Development Kit, which support C and minimal C++ for Native Android hybrid development.

The thing is like this:
We create a Java Android Project which is running under Dalvik Virtual Machine, then we call our shared object library created by C using NDK by calling System.LoadLibrary(blah). And we can access the library in C using JNI (Java Native Interface), then JNI will lookup for a cryptic naming of function inside C. Man, too complex in setting it up.

Now, I have to download the toolchain for compiling the Android C native into Arm library, go to sourcery arm eabi and download it, try to build the JNI project using make APP=blah, got it working, and I see some native C running on my emulator.

Then move on to the next step I want to make use OpenGL, but then I saw in some docs that I need Bionic, what the hell? Another dependencies, this is one of the reason why I don’t like opensource, too much dependencies separated. OK, where should I get this Bionic? Digging, I found it on Android Source Code.

Wow, great, it’s 2.1GB, and my internet only 5KB/s download rate, I go to internet cafe looking for a way to download it without using linux and mac, and I just found out, WebGit can be used to download the snapshot of each project inside https://android.git.kernel.org/ using browser by adding command to it.

I want to download Bionic, then I have this project path: platform/bionic.git

Throw an url like this: https://android.git.kernel.org/?p=platform/bionic.git;a=snapshot;h=HEAD;sf=tgz, I can download the snapshot of the bionic project in tgz format, pretty neat.

The sad thing now… I have to download one by one this lot of projects. I don’t want to write the html javascript code to automate the download, so just be it, download it when I have time.

See, Android made development for newbie is tricky unlike iPhone, two thumbs for Apple SDK.

Another thing… Why Android using Java anyway? it’s so slow…. the Garbage Collection is killing me in the realtime opengl app.

Categories: Android