【发布时间】:2023-04-01 14:20:01
【问题描述】:
我的片段中多次需要上下文:
...
account.restore(getContext());
...
dbHelper = new DBHelper(getContext());
...
DiskLruBasedCache.ImageCacheParams cacheParams = new DiskLruBasedCache.ImageCacheParams(getContext(), "CacheDirectory");
...
mImageLoader = new SimpleImageLoader(getContext(), cacheParams);
...
Toast.makeText(getContext(), "err: " + error, Toast.LENGTH_LONG).show();
...
RecyclerView.LayoutManager layoutManager = new CustomLayoutManager(getContext());
...
或者我应该初始化一次然后使用它。
什么是最好的方法?
【问题讨论】:
-
private Context = getContext()不起作用 -
private Context = getContext()不会编译。
标签: android