I have a condition when a specific event will occur in background, I have to show a Floating Action Button in bottom of activity to notify the user if App in fore ground. No matter in what activity the user is, if that event trigger by a service, I have to show a FAB not a dialog, I mean user can interact with activity and FAB both at the same time. How could I achieve this if I do not wanna repeat the same code in all activities of my app.
Asked
Active
Viewed 109 times
-1
-
Have you considered "including" layouts ? – Mohammed Aouf Zouag Dec 03 '15 at 10:40
-
this is what `Notification`s are used for – pskink Dec 03 '15 at 10:42
-
For this purpose, I would have used `Snackbar` – lee Dec 03 '15 at 10:45
-
I am working with geofences and if the geofence breached and app is in open state, I wanna show a FAB with some animation, In this case Notifications are of no use.. – Mahendra Chhimwal Dec 03 '15 at 10:46
-
People just down vote the question if don't have any answer to question. I am asking for help in design show i prevent some code duplication in all activities. – Mahendra Chhimwal Dec 03 '15 at 10:49
-
@lee Thanks, Thats what I think of very first time but I just have to show a FAB that will remain in any activity till some user does not exit geo fence. Snakebar covers a lot of part of activity. So I have to drop the plan of using it for now. – Mahendra Chhimwal Dec 03 '15 at 10:55
-
`FloatingActionButton` is just a custom `android.widget.ImageView` so simply add it to the root `ViewGroup` by calling `ViewGroup#addView`, what is the problem with that? – pskink Dec 04 '15 at 08:55
2 Answers
2
You can make a utill class and make a static method in that class so in which activity you want to access that method just Classname.methodname and send parameter. or you can use that method in that Activity and extend from that activity

curiousMind
- 2,812
- 1
- 17
- 38
0
You can create a simple activity that matches your need and make all other activities derived (inherited) from that one.

lin
- 108
- 2
- 6
-
But all activities has its own layouts, I just need to show a FAB or any view in any currently opened activity, So i am not using any content_view for BaseActivity. – Mahendra Chhimwal Dec 03 '15 at 10:48
-
Yes, you have to create layouts for each activity, but you don't have to write redundant java code. – lin Dec 03 '15 at 10:53