views:

150

answers:

4

First and foremost, are there many android developers here? Is this a good place for Android related discussions?

I seem to be missing a rather large concept of Android development. The gist is I am struggling understanding how to tie an application together. I’m not sure how to explain it, so I thought I would do my best with an example from the Android ApiDemo… assuming you are familiar with it.

Inside the com.example.android.apis.view namespace of the ApiDemo, there is a class called Animation3.java. Animation3 inherits the activity class and there is some code inside to display animation. I can’t find a reference to the class (Animation3) anywhere in the demo’s code (except for its definition obviously). The only mention I found is in the manifest xml file. So how the heck does this activity get started? Don’t we need to create an instance of the class somewhere and fire off a method to start it? I don’t understand how to generate the code that ultimately glues this class to the rest of the application.

Additionally, what about other classes like views or viewgroups? How do I generate code outside the class that initiates/starts/uses/calls (insert proper term) the class.

I would appreciate any code examples as well as any concept explanation or reference documents. So far I’ve read pages and pages on activities and views but I’m really struggling how to tie things together.

Thanks for all your help.

+1  A: 

Let me take a crack at this.

I'm going to guess that your animation3.java class extends activity (which you said) In android, to switch between activity to activity, you have to declare it as an Intent (look that one up, it's important) and then switch to the other activity.

Here's a simple explaination of how things work.

you use a layout to put things onto the screen a 'view' is an item on your layout, i.e. buttonVIEW, textVIEW etc. this was confusing for me when i started.

you tie all your views into your activity in the onCreate method that is automatically generated when you create an activity in eclipse (unless you have some other autocomplete settings)

that should start getting you on your feet. any other questions? -M@

John Moeller
I think this is where my disconnect lies. I understand the onCreate method (I think). This is the method that is invoked when the Activity is created....so what is the method that actually CREATES the activity and thus invokes the onCreate method?
That method is internal to the Android SDK. You don't need to worry about it, all you need to do is create an Intent that and call startActivity(intent) with that intent. Then, onCreate in your activity will be called.
Mayra
be careful to note that all active data from your old activity might be lost / stepped on, so think about passing data (as a bundle) or attempting to save it to a simple DB. The method that CREATES the activity is a built in method on android (I think) and part of the android OS. (IE it's the wind! You can't touch it or see it unless you are on god mode... j/k)
John Moeller
+2  A: 

The manifest declares the entry point for the application, that is to say that if you see the following lines in your manifest -

            <?xml version="1.0" encoding="utf-8"?>
            <manifest xmlns:android="http://schemas.android.com/apk/res/android"
                  package="com.domain.android.myapp"
                  android:versionCode="15"
                  android:versionName="2.7.1">

                <application android:icon="@drawable/icon" 
                    android:label="@string/app_name"
                    android:debuggable="true"
                    >
                    <activity android:name=".MyApp"
                              android:label="@string/app_name"
                              android:theme="@android:style/Theme.NoTitleBar"
                              >
                               <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

then it means that the manifest is instructing the runtime to use that class (MyApp) as the main entry point for the application.

arunabhdas
I'll have to mull this over some more, but a question. What about a class that isn't the main entry point? Can XML be used in the same way as an entry point into that class/activity?
A: 

look at android dev guide:

http://developer.android.com/guide/index.html

however, your default activity can be instantiate and called by android framework itself. just like main mathod in a normal java application.

your default activity will define in the xml file that you mentioned.

mohammad shamsi
A: 

on one leg android main concept is

  1. your xmal as the graphic entity and the code behind
  2. a code that you bind to your graphics usually inherits from activity 3.every application has its own manifest

every application has her own first class , the startup class which is defined in the manifest
like this :

<application android:debuggable="true" android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".startupclass"
              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 =".secondClass" ></activity>  
<activity android:name =".thiredClass" ></activity>  

for more info why activity and what are the other entities provided by android please visit :

http://developer.android.com

if you have any other questions fell free to ask

yoav.str