How to send objects through bundle

前端 未结 11 1279
我寻月下人不归
我寻月下人不归 2020-11-27 13:15

I need to pass a reference to the class that does the majority of my processing through a bundle.

The problem is it has nothing to do with intents or contexts and ha

11条回答
  •  甜味超标
    2020-11-27 13:36

    This is a very belated answer to my own question, but it keep getting attention, so I feel I must address it. Most of these answers are correct and handle the job perfectly. However, it depends on the needs of the application. This answer will be used to describe two solutions to this problem.

    Application

    The first is the Application, as it has been the most spoken about answer here. The application is a good object to place entities that need a reference to a Context. A `ServerSocket` undoubtedly would need a context (for file I/o or simple `ListAdapter` updates). I, personally, prefer this route. I like application's, they are useful for context retrieving (because they can be made static and not likely cause a memory leak) and have a simple lifecycle.

    Service

    The Service` is second. A `Service`is actually the better choice for my problem becuase that is what services are designed to do:
    A Service is an application component that can perform long-running operations in
    the background and does not provide a user interface.
    
    Services are neat in that they have a more defined lifecycle that is easier to control. Further, if needed, services can run externally of the application (ie. on boot). This can be necessary for some apps or just a neat feature.

    This wasn't a full description of either, but I left links to the docs for those who want to investigate more. Overall the Service is the better for the instance I needed - running a ServerSocket to my SPP device.

提交回复
热议问题