简体   繁体   中英

Not understanding a basic concept of Android application development

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.

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>
  </application>
</manifest>

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

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, ie 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@

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM