Android: Visual A/B Testing library

178 views Asked by At

I am developing a small A/B Testing library for Android. Library will only be initialised in application class. I need to change TextView values.

I will store all the data fetched from the in a file. But I am not able to track when ever a TextView gets into view and moves it. For example TextView A is in X Activity, TextView B is in Y Activity and TextView C is in Z Activity. Since the variable I have is Context, how should I change TextView A, B, C values.

I need to figure out which Activity is Visible. From the Activity I will be able to get root view. And I will iterate over child views and change value. But How should i listen to Activity Change.

Is there any other approach to this ?

I know this is possible as many A/B testing library are doing this.

2

There are 2 answers

0
Vic Vuci On

Here you go, check out my answer over Here

As you've mentioned, hooking into the activity lifecycle callbacks via AppContext is the best way to start. From there, you'll have all of the information you could possibly need. Every time the activity switches, you'll have the Activity object, and from there you can get the root view and apply changes as necessary.

I would advise against an iteration over the views though! If you have the rootview, you can just do a findViewId(textview C id) on that root view and you'll grab your view!

0
Amit Gupta On

Since you are building a library, you can expose a function which can be called after onCreate of each activity, which will give you reference of the activity. Once you have the activity, you can get it's root view and do whatever magic you want to do.

That's the only other approach if you don't want to register LifeCycle callbacks for activity. The application needs to enter your library at least at some point of time. Either you can make the application do manually ( above approach ) or you can override all life cycle events of all activities ( registering lifecycle call back ).