覆盖Android所有活动的OnResume()方法 [英] Override OnResume() method of all activities Android
问题描述
我的应用程序有10多个活动,我想在所有活动中使用相同的代码覆盖方法onResume()
.
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.
此外,我想在此onResume中显示一条消息,该消息取决于活动的来源,例如:如果您在MainActivity中,则我希望此常见的onResume检测到该活动来自此活动并显示I'm coming from MainActivity
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
谢谢.
推荐答案
您应在BaseClass
中使用Override
活动,并在其他活动中使用BaseClass
代替活动":
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
{
}
这篇关于覆盖Android所有活动的OnResume()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!