I have an app that has one main activity with FrameLayout. Many fragments are created according to users' input. Every fragment has one admob banner ad using Adview
.
I add fragments using the code;
getSupportFragmentManager().beginTransaction()
.add(R.id.container, Constants.frg1, Constants.frgTag1)
.addToBackStack(Constants.frgTag1)
.commit();
I don't want to use transaction.replace()
method because I don't want my previous fragment to be recreated when backpressed that all fragments are getting data from a remote server.
So when I add new fragment a new Adview is created inside the new fragment in onCreateView
method.
After get around 10 fragments my app starts to get laggy. When I dont use Adview there is no problem with the performance.
You can say that I can use only one Adview inside the MainActivity that contains the fragments but I dont want that because I have a BottomNavigationView that is visible along the application. BottomNavigationBar + Adview = very little place remains for my app content in the screen.
So is there any idea to optimize my app performance using many fragment and each has its own AdView
?