Preface:
Currently, the development of the Android platform is booming. it is not difficult for programmers with Java development experience to switch to the Android platform. Therefore, this series of articles uses the actual practices of the pocket Chinese Android edition project as an example to explain relevant knowledge points, so as to lead more people into the embrace of Android development :)
Preparations:
1,To build an Android mobile client, you must first build an android development environment. You can refer to this post:
Full demonstration of building the android Development Environment (JDK + eclip + Android SDK)
2,To learn about some basic concepts of Android, such as the basic concepts of Android development, application entry points, interface switches, and event responses, please refer to the Android Application Development details in this book.
3,To write custom Android UI and improve user experience, see this book from scratch android game programming PDF
Write code:
Generally, software startup is a welcome interface, that is, a pop-up screen in terms of software. For this client:
The XML layout of the pop-up page is as follows:
<?xml version="1.0" encoding="UTF-8"?><AbsoluteLayoutandroid:background="@drawable/welcome"android:id="@+id/widget39"android:layout_width="fill_parent"android:layout_height="fill_parent"xmlns:android="http://schemas.android.com/apk/res/android"><ProgressBar android:layout_width="160px" style="?android:attr/progressBarStyleHorizontal" android:progress="100" android:id="@+id/loading" android:layout_height="wrap_content" android:layout_x="64dip" android:layout_y="264dip"> </ProgressBar><TextView android:layout_width="wrap_content" android:id="@+id/tips" android:layout_height="wrap_content" android:gravity="center" android:text="please wait" android:layout_x="120dip" android:layout_y="228dip"> </TextView></AbsoluteLayout>
From the code above, we can see that the welcome page contains a background image, a text, and a progress bar.
The following code generates a welcome page using the preceding layout file:
package com.pocketcn.ui;import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.widget.ProgressBar;import android.widget.TextView;import java.util.Timer;import java.util.TimerTask;import com.pocketcn.ui.R;public class splash extends Activity {/****/static int idx=0;/****/protected ProgressBar myProgressBar;/****/protected TextView tips;protected Timer tr;private Handler process=new WelcomeProc(this);/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle icicle) {super.onCreate(icicle);setContentView(R.layout.splash);tips=(TextView)findViewById(R.id.tips);myProgressBar=(ProgressBar)findViewById(R.id.loading);//tr=new Timer();tr.schedule(new TimerTask(){@Overridepublic void run() {splash.idx++;process.sendEmptyMessage(splash.idx);}}, 0,200);}}
In the above Code, myprogressbar is a progress bar control. This progress bar control needs to be updated based on the current data processing status. Therefore, I use a handler for communication, to notify the activity to update the corresponding control, the Code is as follows:
Package COM. pocketcn. ui; import android. app. activity; import android. OS. handler; import android. OS. message; import COM. pocketcn. UI. r; Class welcomeproc extends handler {Private Static activity res; Public welcomeproc (activity athis) {This. res = athis;} @ overridepublic void handlemessage (Message MSG) {int PRC = MSG. what; If (PRC> 0) {(splash) RES ). tips. settext ("Tips:" + Res. getstring (R. string. welcometips1 ));} If (PRC> 30) {(splash) RES ). tips. settext ("Tips:" + Res. getstring (R. string. welcometips2);} If (PRC> 60) {(splash) RES ). tips. settext ("Tips:" + Res. getstring (R. string. welcometips3);} If (PRC> 100) {/* Start the main interface intent = new intent (); intent. setclass (Res, splash. class); Res. startactivity (intent); */If (splash) RES ). tr! = NULL) {(splash) RES ). TR. cancel ();} // change the layout (splash) RES ). setcontentview (R. layout. main); return;} (splash) RES ). myprogressbar. setprogress (PRC );}}
Download the source code of this series of articles:
Full history of development of Android Client 1.0 in pockets China
Http://www.pocketcn.com/forum-viewthread-tid-1490-fromuid-2.html
The second logon interface for full-process recording of pocket China Android Client Version 1.0
Http://www.pocketcn.com/forum-viewthread-tid-1585-fromuid-2.html
Pocket China Android Client 1.0 full development record 3 user entity class
Http://www.pocketcn.com/forum-viewthread-tid-1744-fromuid-2.html
Four logon functions recorded throughout the development of pocket Chinese Android Client 1.0
Http://www.pocketcn.com/forum-viewthread-tid-1882-fromuid-2.html
Five Forum entity categories recorded throughout the development of pocket Chinese Android Client 1.0
Http://www.pocketcn.com/forum-viewthread-tid-1894-fromuid-2.html
Pocket China Android Client 1.0 full development record 6 registration page
Http://www.pocketcn.com/forum-viewthread-tid-1916-fromuid-2.html