java - Retain Fragment data without retaining Fragment -
i'm working on app, needs lots of calculations in background.
start thread fragment , pass handler it, can pass messages back. when configuration change occurs (screen rotation, ...) android recreates activity , fragment. i'm looking way reference thread new fragment, can pass new handler it.
retaining whole fragment not option me, uses different layout in landscape mode.
i can't use onretainnonconfigurationinstance(), supported on activities, thread lives in fragment.
i can't use onsaveinstancestate(), supports primitive data types.
are there other ways me retain reference background thread when fragment recreated?
i solved problem using headless retained fragment, manages thread.
my normal fragment creates new instance of headless fragment, retained. headless fragment has start()
, stop()
methods, in turn start , stop thread , sethandler()
method, changes handler messages passed to.
whenever non retained fragment recreated has retained fragment fragmentmanager , call sethandler()
new handler.
Comments
Post a Comment