How to development a Android App

Before you begin, Let’s talk about Android lifecycle first . Learn about Android’s four major components,And to be familiar with Android development tool -Android Studio.

Activity


1
2
3
4
Activity1->Activity2: onCreate()——>onStart()——>onResume()
Note left of Activity2: 第一个 Pause,第二个Create,Start,Resume。第一个 Stop
Activity2-->Activity1: back to the activity1
Note left of Activity2: 暂停,restart第一个,start,resume,第二个stop,destory.

when you push a new Activity or back Activity, it’s due to the stack to manage the Activity status, but how to push a new Activity?

1
2
3
4
5
Intent intent = new Intent(ReorderFour.this, ReorderTwo.class);    

intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);

startActivity(intent);

Activity Extented

after we know the android activity, i want tall about fragment.

Perhaps you have seen the most app interfaces is like this. YEs ,it’s Tabbar UI Interface.

效果图

picture1picture2
picture1picture1

so, what about the fragment ?
  1. tabbar interface is a activity contains one or more fragments.
  2. fragments lifecycle is rely one activity.
what did I do to make layout the UITabarActivity?

app gradle 配置

picture1

项目结构

picture2

Tabbar Activity

picture1

Layout 布局

picture1

界面Fragment配置

picture1

ok,after you see my screenshots, you can know , i use the ViewpagerIndicator to make a tabbar Activity . it can manager fragments. you can easy to change every fragment you need.

app gradle instroduce

1. use the fastjson to make json parse.
2. use the butterknife replace the frequent findViewById.
3. use the ViewPagerIndicator to achieve a tabbarActivity interface.
4. use the android-smart-image-view to make the image cache.
5. use the android-async-http to make http request.
6. use the recycleView-v7 replace the android system listView.
7. use the bga-refreshlayout to make the pull refresh cool header.
8. finally, use cn.bingoogolapple:bga-adapter to make the recycleView cell Item can right move delete, long press event ,ItemChildClickListener ,and so on . all in all, bga-adapter is perfect !

For your convenience, i encapsulated a tableview like iOS UITableView , you can use the group style or plain style decide by youself; you can find it in the package com.lvj.bookoneday->widget.view

tableview like iOS UItableView

1
2
3
4
5
6
//定义表格的数据源接口
public interface TableViewDataSource<T> {

RecyclerViewCell<T>[] getRecyclerCells(); //获取cell
int getItemViewType(int position); //获取position: cell类型的tag
}
1
2
3
4
5
6
7
8
9
10
//定义表格的事件委托源
public interface TableViewDelegate {

void onTableViewDidSelectRow(int row);//点击单行
void onTableViewDidLongClickRow(int row); //长按单行
void onTableViewDidChangeCheckRow(int row, boolean isChecked); //选中行
void onItemChildClick(View childView, int position); //item 点击
void onTableViewRefresh();//下拉刷新
void onTableViewLoadMore(); //加载更多
}
  • I create two java interface : TableViewDelete, TableViewDataSoucre. that you can easy
    implements there’s methods .
  • when you use the activity or fragment need tableView layout , you can easy and fast
    layout ,and implements TableViewDelegate, TableViewDatasource.

for examples

tableview like iOS UItableView

Talk about Http request

you know, when your app ask a request, may be have two Design Patterns . it named “block”(anonymous inner classes) ,”delegate”(delegate is named by iOS. on java, it’s interface or ask “OOP” thoughts).

My HttpRequest Design

there is a abstract class named BaseDataService. if you have a new request . you just extend BaseDataService and @Override three methods. “getAPIRequestMethodName
, setRequestParams,parseResponse”. look these screenshots. And on your Activity or Fragments , you just implemets RequestCallBackDelegate , and you can use your son of BaseDataService to make some request.

父类

tableview like iOS UItableView

子类继承父类

tableview like iOS UItableView

界面用子类请求实现

tableview like iOS UItableView

For more info about the tableView how to work, you can find my open source on my Github Android-TableView,welcome make you suggestion. if you like this project, on my github, I hope you can click on the star in the upper right corner to give me more encouragement. thank you!

TO Do: Introduce Android Service components

评论