Summary of the design ideas of Android app program

Source: Internet
Author: User
Tags format definition

A summary of the design ideas of Android app program design and implementation of model

Establish business Pojo, such as user

public class User{    private int userId;    private String userName;    public User(int userId, String userName){        this.userId = userId;        this.userName = userName;    }    public void setUserId(int userId){        this.userId = userId;    }    public void setUserName(String userName){        this.userName = userName;    }    public int getUserId(){        return this.userId;    }    public String getUserName(){        return this.userName;    }}
Design and implementation of interface between two and net networks

1, request the format definition.

http://192.168.1.31/CommandHandler.ashx{"MessageContent":"{‘CourierId‘:‘652‘,‘TrackingY‘:31.174406,‘Province‘:‘上海市‘,‘District‘:‘闵行区‘,‘City‘:‘上海市‘,‘TrackingX‘:121.39061,‘Address‘:‘上海市闵行区万源路2163号‘}","Passport":"mWEKICmWIVD0YRGXMSRC5HH7SYVMIVlVEGOMRK","Function":"AddCourierTracking","Usage":"User"}

2, return format definition

{"ResultFlag":1,"ErrorMessage":null,"Passport":"mWEKICmWIVD0YRGXMSRC5HH7SYVMIVlVEGOMRK","MessageContent":{\"Result\":null,\"ResponseStatus\":{\"ErrorCode\":\"1\",\"Message\":null,\"StackTrace\":null,\"Errors\":null}}}

3, the implementation method needs to adapt to a variety of situations (method overloading), internal implementation needs to avoid duplication (cohesion).

public class NetUtil{    public static void doPost(Context context, HashMap<String,String> map, Handler handler, Callback callBack){        doRequest(context, map, handler, callBack);    }    public static void doGet(Context context, Handler handler, CallBack callBack){        doRequest(context, null, handler, callBack);    }     private static void doRequest(Context context, HashMap<String,String> map, Handler handler, Callback callBack){        ...    }}
Third, UI interface framework

1, define your own superclass such as MyActivity, myfragment

public class MyActivity extends Activity{}

2, set up the Super-class chain (), insert the log, Toast, progress bar, navigation bar, title bar and other common UI elements, separately inserted is to facilitate the expansion and removal.

public class LoggableActivity extends Activity{    protected static String TAG = this.getClass.getSimpleName();    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        LogUtil.log(TAG,"onCreate()");    }}

3, respectively, to implement the individual pages, inherited from the lowest level of super class.

public class LoginActivity extends LoggableActivity{}

4,adapter,service,broadcast and other similar.

Iv. Management Data

1, use ContentProvider.

2, use SQLite.

3, File mode storage (sharedperference, SD card) need to add encryption and decryption.

4, use a memory cache policy, such as the LRU algorithm.

V. Release and Proguard

1, all classes defined by Androidmanifest.xml cannot be confused, so the key business logic implementation removes the called class.

2, the referenced third-party package cannot be confused.

Summary of the design ideas of Android app program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.