Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FragmentManager from application context

Is there a way to get FragmentManager from application context? I want to use ImageLoader or BitmapFun to store some bitmaps that I download from server. Both class require a FragmentManager to use to retain the cache over configuration changes such as an orientation change. In my case I want to pre-download the images before I actually "need" them.

like image 334
learner Avatar asked Mar 21 '14 14:03

learner


People also ask

What is the difference between FragmentManager and supportFragmentManager?

These two classes are clearly related. Is SupportFragmentManager used for Fragments generated using FragmentTransaction , while the "regular" FragmentManager is used exclusively to test Fragments generated using .

What is the function of the FragmentManager?

The FragmentManager manages the fragment back stack. At runtime, the FragmentManager can perform back stack operations like adding or removing fragments in response to user interactions. Each set of changes are committed together as a single unit called a FragmentTransaction .

What is FragmentManager in android?

A FragmentManager manages Fragments in Android, specifically it handles transactions between fragments. A transaction is a way to add, replace, or remove fragments.


2 Answers

Is there a way to get FragmentManager from application context?

No, because fragments are part of an activity.

In my case I want to pre-download the images before I actually "need" them.

Then use a different library, one that does not have a dependency upon fragments.

like image 110
CommonsWare Avatar answered Oct 07 '22 19:10

CommonsWare


Yes, you can.

First you have to read this solution to get the "Current activity" of your application:

How to get current foreground activity context in android?

Activity activity = ((myApplication) getApplicationContext()).getCurrentActivity();    
FragmentManager fragmentManager = activity.getFragmentManager();
like image 41
toni Avatar answered Oct 07 '22 19:10

toni