Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
916 views
in Technique[技术] by (71.8m points)

service - Android - Good Practice Activity and Lifecycle

I working on a library project and I'm facing some "issues", I don't have setup Dagger, RX or any of these things for now because I try to face the problem that should put me on this way

First is : In this project I have a BroadcastReceiver class that work well, but this broadcast receiver is register and unregister by me into onStart() and onStop() method of my demo activity

 ```override fun onStart() {
        super.onStart()
        registerReceiver(myReceiver, IntentFilter(TOTO))
    }

 override fun onStop() {
        super.onStop()
        unregisterReceiver(myReceiver)
    }```

Second is : In this project I also have an IntentService, that the user can start and also bind to communicate with, but I also do the unbind() action into a lifecycle method

but I don't want to force the user to do that for each of activities that implement my library, so I think about a solution : Create an Activity that should be override to already implement all this lifecycle stuff

But i'm wondering if with AAC and all Fancy Lib we use these day, if there is a way to do that more cleanly ? ( Like using LiveData or I don't know )

Thanks you a lot for reading me and maybe participate to the discussion :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...