我需要的情況下多次在我的片段:許多「getContext()」或一個私有上下文= getContext()並使用它?
...
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()'不會編譯。 –