gru*_*unk 11 android android-context
根据这个答案或android的文档,有几种方法可以在应用程序中获取Context并将其传递给其他类/方法/ anyuneed.
假设我在Foo活动中并且需要将上下文传递给Bar的构造函数.
Bar bar = new Bar(Foo.this);
Bar bar2 = new Bar(this); //same as first i guess
Bar bar3 = new Bar(getApplicationContext());
Bar bar4 = new Bar(getBaseContext());
Bar bar5 = new Bar(MyApp.getContext); // get context statically
Run Code Online (Sandbox Code Playgroud)
考虑到内存泄漏,速度,一般性能,所有这些可能性之间的更好方法是什么?