本文主要是介绍android 获取顶部栈点stack的Activity以及上下文Context,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、获取顶部栈点的Activity的上下文Context
MyApp.getApplication().getNowTopContext();
public class MyApp extends Application {
public static MyApp application;
@Override
public void onCreate() {
super.onCreate();
this.application = this;
initLifecycle(this);
}
public static MyApp getApplication() {
return application;
}
public Context getNowTopContext() {
return mContext == null ? null : mContext.get();
}
public WeakReference<Context> mContext;private void initLifecycle(Application application) {application.registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {@Overridepublic void onActivityCreated(Activity activity, Bundle savedInstanceState) {if (activity.getParen
这篇关于android 获取顶部栈点stack的Activity以及上下文Context的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!