package com.lx.activity.task;


import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;


public abstract class CommonActivity extends Activity implements Button.OnClickListener{


private Button btn;

private TextView tv;


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

Log.i("test",this.getClass().getSimpleName()+" -onCreate()");

setContentView(R.layout.main);

btn = (Button)findViewById(R.id.btn);

btn.setOnClickListener(this);

tv = (TextView)findViewById(R.id.tv);


initView();

}


private void initView(){


setBtnName(btn);

setTvName(tv);


}


@Override

public void onClick(View v) {

Intent i = new Intent(this,getNextActivity());

startActivity(i);

}


protected abstract void setBtnName(Button btn);

protected abstract void setTvName(TextView tv);

protected abstract Class getNextActivity();


@Override

protected void onStart() {

// TODO Auto-generated method stub

super.onStart();

Log.i("test",this.getClass().getSimpleName()+" -onStart()");

}


@Override

protected void onRestart() {

// TODO Auto-generated method stub

super.onRestart();

Log.i("test",this.getClass().getSimpleName()+" -onRestart()");

}


@Override

protected void onResume() {

// TODO Auto-generated method stub

super.onResume();

Log.i("test",this.getClass().getSimpleName()+" -onResume()");

}


@Override

protected void onPause() {

// TODO Auto-generated method stub

super.onPause();

Log.i("test",this.getClass().getSimpleName()+" -onPause()");

}


@Override

protected void onStop() {

// TODO Auto-generated method stub

super.onStop();

Log.i("test",this.getClass().getSimpleName()+" -onStop()");

}


@Override

protected void onDestroy() {

// TODO Auto-generated method stub

super.onDestroy();

Log.i("test",this.getClass().getSimpleName()+" -onDestroy()");

}



}


================CommonActivity 结束=================


----Activity1---------

package com.lx.activity.task;


import android.widget.Button;

import android.widget.TextView;


public class Activity1 extends CommonActivity {


@Override

protected void setBtnName(Button btn) {

btn.setText("startActivity2");

}


@Override

protected void setTvName(TextView tv) {

tv.setText("Activity1");

}


@Override

protected Class getNextActivity() {

return Activity2.class;

}


}

-------Activity2---------

package com.lx.activity.task;


import android.widget.Button;

import android.widget.TextView;


public class Activity2 extends CommonActivity {


@Override

protected void setBtnName(Button btn) {

// TODO Auto-generated method stub

btn.setText("startActivity3");

}


@Override

protected void setTvName(TextView tv) {

// TODO Auto-generated method stub

tv.setText("Activity2");

}


@Override

protected Class getNextActivity() {

return Activity3.class;

}


}


---------Activity3-----------

package com.lx.activity.task;


import android.widget.Button;

import android.widget.TextView;


public class Activity3 extends CommonActivity {


@Override

protected void setBtnName(Button btn) {

// TODO Auto-generated method stub

btn.setText("startActivity4");

}


@Override

protected void setTvName(TextView tv) {

// TODO Auto-generated method stub

tv.setText("Activity3");

}


@Override

protected Class getNextActivity() {

// TODO Auto-generated method stub

return null;

}


}



------main.xml-----

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >


<TextView

android:id="@+id/tv"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Activity1"

android:layout_gravity="center"/>


<Button android:id="@+id/btn"

android:text="StartActivity2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="100px"

android:layout_gravity="center"/>

</LinearLayout>

--------AndroidManifest.xml-------

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.lx.activity.task"

android:versionCode="1"

android:versionName="1.0" >


<uses-sdk android:minSdkVersion="7" />


<application

android:icon="@drawable/ic_launcher"

android:label="@string/app_name" >

<activity

android:name=".Activity1"

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=".CommonActivity"/>

<activity

android:name=".Activity2"/>

<activity

android:name=".Activity3"/>

</application>


</manifest>













更多相关文章

  1. android倒计时封装(活动进入后台,倒计时依然能正常计时)
  2. Android:电话拨号器、呼叫记录、结束通话、Android显示单位
  3. Android正确关闭线程
  4. android很简单的天气预报例子和XML解析
  5. [Android设计模式]Android退出应用程序终极方法
  6. Android(安卓)kill app Process 结束进程代码
  7. [Android设计模式]Android退出应用程序终极方法
  8. Android(安卓)开发
  9. android webView判断是否加载完成的2种办法

随机推荐

  1. 增加反向链接的35个技巧
  2. CSS 元素样式来源
  3. 媒体查询移动优先与 PC 优先的区别与联系
  4. vs code的插件配置、markdown和emmet基本
  5. html注册页面-表单
  6. HTML常用标签汇总
  7. 一个网站有多个域名,怎么处理对SEO比较友
  8. 站群团队分工合作细则
  9. 如何找到一个SEO细分市场进行创业?
  10. 学习SEO创业机会怎样?