Override OnResume() method of all activities Android

不问归期 提交于 2019-12-06 21:32:06

问题


I have and app with more than 10 activities and I would like override the method onResume() with the same code in all of them.

I know that I can override this method in each activity, but I'm looking for an efficient solution.

Moreover I would like inside this onResume show a message depending what activity is coming from, for example: if you are in the MainActivity I want that this common onResume detects that is coming from this activity and show I'm coming from MainActivity

Thank you.


回答1:


you should Override activity in a BaseClass and use your BaseClass instead of Activity in the other activities:

public class BaseClass extends Activity 
{

  public void onResume() 
  {
    // common code
  } 
}

public class OtherClass extends BaseClass 
{
}



回答2:


Make a parent activity and override its onResume, then make all your 10 activities extend the creted parent..



来源:https://stackoverflow.com/questions/12617207/override-onresume-method-of-all-activities-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!