How to extend a base activity in android? -


i create option menu in android activity. have many activity want same option menu in activity. know have create base activity , extend don't know how. here main activity code....

            package com.officextracts.kaspersky;          import android.os.bundle;         import android.app.activity;         import android.content.intent;         import android.view.menu;         import android.view.menuitem;         import android.view.view;         import android.widget.button;         import android.widget.imagebutton;         import android.widget.toast;          public class mainactivity extends activity implements view.onclicklistener         {              button button01;              @override             protected void oncreate(bundle savedinstancestate) {                 super.oncreate(savedinstancestate);                 setcontentview(r.layout.activity_main);                 button01 = (button)findviewbyid(r.id.button01);                 button01.setonclicklistener(this);             }              private void button1click()             {                 startactivity(new intent("com.officextracts.kaspersky.retail_products"));              }              public void onclick(view v) {                 switch (v.getid())                 {                 case r.id.button01:                     button1click();                     break;                 }               }              @override             public boolean oncreateoptionsmenu(menu menu) {                 // inflate menu; adds items action bar if present.                 getmenuinflater().inflate(r.layout.menu, menu);                 return true;             }             @override             public boolean onoptionsitemselected(menuitem item)             {                  switch (item.getitemid())                 {                 case r.id.menu_home:                     // single menu item selected                     // ex: launching new activity/screen or show alert message                     toast.maketext(mainactivity.this, "home selected", toast.length_short).show();                     return true;                  case r.id.menu_krp:                     toast.maketext(mainactivity.this, "kaspersky retail products", toast.length_short).show();                     return true;                  case r.id.menu_kep:                     toast.maketext(mainactivity.this, "kaspersky endpoint products", toast.length_short).show();                     return true;                  case r.id.menu_fkr:                     toast.maketext(mainactivity.this, "find kaspersky resaller", toast.length_short).show();                     return true;                  case r.id.menu_sales:                     toast.maketext(mainactivity.this, "contact kaspersky sales", toast.length_short).show();                     return true;                  case r.id.menu_crs:                     toast.maketext(mainactivity.this, "contact retail support", toast.length_short).show();                     return true;                  case r.id.menu_ces:                     toast.maketext(mainactivity.this, "contact enterprise support", toast.length_short).show();                     return true;                   case r.id.menu_coo:                     toast.maketext(mainactivity.this, "contact our office", toast.length_short).show();                     return true;                   case r.id.menu_sms:                     toast.maketext(mainactivity.this, "sms support", toast.length_short).show();                     return true;                   case r.id.menu_email:                     toast.maketext(mainactivity.this, "email support", toast.length_short).show();                     return true;                              case r.id.menu_exit:                     finish();                     system.exit(0);                                  default:                     return super.onoptionsitemselected(item);                 }             }             } 

create activity can abstract class extending activity. each new activity has extend class. eg:

//your base class, can have action bar , other other methods want other classes inherit public abstract class abstractactivity extends activity{}   // other classes public class firstactivity extends abstractactivity{} public class secondactivity extends abstractactivity{} 

see android how create own activity , extend it? question

common header in different activities using baseactivity in android

android: base activity class example more.

hope helps.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -