Questions tagged [headless-fragments]

Fragments which can be used without defining a user interface.

Description

Headless fragment are typically used to encapsulate some state across configuration changes or for a background processing task. For this purpose you would set your headless fragment to be retained.

Fragments can be used without defining a user interface.

To implement a headless fragment, simply return null in the onCreateView() method of your fragment.

It is recommended to use headless fragments for your background processing in combination with the setRetainInstance() method. This way you don't have to handle the configuration changes during your asynchronous processing yourself.

Link

vogella

7 questions
25
votes
3 answers

What is the difference between a Headless Fragment and a Service in Android?

Service A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use. Headless Fragment Fragments…
Yesha
  • 381
  • 1
  • 4
  • 13
2
votes
0 answers

A good way for communication between retained fragments

I have several retained fragments in my activity (up to 3) that are in charge of making different small task using asynkTask (from now smallRetainedFragments). The documentation says is a good practice to centralize the communication between…
0
votes
1 answer

I'm trying out HeadlessUI, Tailwind 2, and VueJS v3. Why do I have to click on the HeadlessUI SwitchLabel, before the Switch component appears?

I'm trying out HeadlessUI v1.0, Tailwind v2.2, & VueJS v3 (so cutting edge, I know). But why do I have to click on the SwitchLabel, before the Switch component appears? Once the Switch appears, both states appear/function normally. Is there…
Paul Brady
  • 503
  • 4
  • 10
0
votes
1 answer

Will using Asynctask in another class or in a headless fragment still cause memory leak?

I have read that using asynctask as an inner class of an activity will cause memory leaks because it won’t let the activity get garbage collected and also due to implicit referencing as well. Will the same memory leaks occur if we used different…
0
votes
1 answer

AsyncTask survived screenOrientation without headless fragment

I am trying to know how to make the AsyncTask survives the screenOrientation change. So, I created an example for a MainActivity with AsyncTask. As shown in the code below, in the doInBackground() method I print the incremented value of the…
Amrmsmb
  • 1
  • 27
  • 104
  • 226
0
votes
0 answers

Activity is null while calling headless fragment

I have a headless fragment to ask permissions in run-time for Marshmallow devices. public class ReadContactPermissionHelper extends Fragment { private static final int REQUEST_READ_CONTACT_PERMISSION = 9001; public static final String TAG =…
0
votes
1 answer

How to display / kill Async task output - original activity killed & completely different activity started

I have been trying to develop an in app billing feature in my app and even though using headless fragment to actual do the in app billing, makes more sense after seeing this -…