Results tagged “android” from muse

How to start a new Activity

|

Android has a weird way of constructing UI. At least I haven't got used to it.

First of all, AndroidManifest.xml must have activities listed:


<activity android:name=".FirstActivity" android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>


<activity android:name=".SecondActivity" android:label="Second Activity">
    <intent-filter>
        <action android:name="com.example.app.activities.SECOND" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

There are several ways to set the components (action, type, category) of Intent, below are the 2 easiest ways.

Intent i = new Intent();
i.setAction(“com.example.app.activities.SECOND”);

Or this:

i.setClass(getApplicationContext(), SecondView.class);

Create a bundle to pass data to the new activity:

Bundle bundle = new Bundle();
bundle.putString("TEXT", "Lorem ipsum");
i.putExtras(bundle);

To start the activity:

startActivity(i);

To get the data from the bundle that’s passed to our new activity:

Bundle bundle = getIntent().getExtras();
String prompt = bundle.getString("TEXT");

Starting Android Development

|

I decided earlier this week that it’s time to see how developing on Android feels like, and installed Eclipse and the ADT plugin. Setting up the development environment was pretty fast; took about 5 minutes.

Here is a screenshot of the Android Emulator running my HelloWorld app. android-emulator.jpg

The emulator takes a while to boot (the first time I ran it I thought it froze so I force quitted it). I’m running Leopard on my macbook pro and I every time I start the emulator I get this waring: “Warning once: This application, or a library it uses, is using NSQuickDrawView, which has been deprecated. Apps should cease use of QuickDraw and move to Quartz.” It doesn’t affect the emulator in anyway so there is nothing to worry about; just ignore it. This issue might be addressed in future versions.

Here’s some links: