How to do code reuse for android activities?

code reuse for activity is confusing. In normal situation we can design a parent activity and put all common method in it. like follow : public class BaseActivity extends Activity{ @Override protected void doExit() { showDialog(DIALOG_EXIT_ALTER); } protected Dialog onCreateDialog(int id, Bundle args) { switch (id) { case DIALOG_EXIT_ALTER: return new AlertDialog.Builder(BaseUIActivity.this) .setTitle("Exit?") .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialoginterface, int i) { close(); } }) .setNeutralButton("No",null).create(); default: return null; } } protected void close() { finish(); } } then other activities extend BaseActivity will show a alertdialog instead of exit immediately when back button press. But in android framework there are more than one build-in activites such like PreferenceActivity,ListActivity,ActivityGroup,etc. if my activity extend those activities then it can't use the common code defined in BaseActivity.because of Java's single inheritance. So is there other way recommend to do code reuse for activity in android?

以上就是How to do code reuse for android activities?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准