1 / 7

Linear Programming Persistent Data

Linear Programming Persistent Data. “Call Back” programming Persistent Data. onLoad. Declare GUI & Data. Framework. On Gui Event. Operate on GUI & Data. Gui and Data objects persist until explicitly destructed. All Gui and Data objects are accessible

neron
Télécharger la présentation

Linear Programming Persistent Data

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linear ProgrammingPersistent Data

  2. “Call Back” programmingPersistent Data onLoad Declare GUI & Data Framework On Gui Event Operate on GUI & Data Gui and Data objects persist until explicitly destructed. All Gui and Data objects are accessible since they are declared in common code.

  3. For Android onCreate Declare GUI & Data Framework On Gui Event Operate on GUI & Data onDestroy Destruct (can occur at any time w/o your consent) • Gui and Data Do Not Persist • References to Gui objects can not be held “globally”, since those objects don’t persist. • One Activity can not reference objects or data in another Activity.

  4. A Proper Android Solution • Put common, persistent code in a Service. • Invoke Activities, as needed, from the Service. • Keep most (if not all) persistent state in the Service – not in the Activities. • Con: • Overhead of the Activity-Service communication mechanism (from both coding and runtime perspectives).

  5. An Alternative Solution • Put common, persistent code in the Application Class, or a class referenced from the Application Class. • Keep persistent state in both the Application Class and the Activities. • Con: • Need to keep the Application Class alive.

  6. Declaring and Using an Application Class 1. Extend the Framework Application public myApplicationClass extends android.app.Application 2. Access the Application class from any Activity (myApplicationClass) this.Activity.getApplication(); 3. Use a trivial service to keep the Application alive a) tell framework to put service in foreground and give it a notification object. [ Service.startForeground() ] b) periodically send a message from the service to the Application and send a message back to the service.

  7. Final Thoughts The Proper Android approach is more reliable and thus a better solution. The Application Class approach has its usefulness in particular, when porting from a more classical model.

More Related