Android: Visual A / B Testing library

I am developing a small A / B test library for Android. The library will only be initialized in the application class. I need to change the values ​​of the TextView.

I will save all the data extracted from the file. But I cannot keep track of when ever the TextView comes 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 has a context, how do i change the values ​​of TextView A, B, C.

I need to figure out what activity is visible. From the Activity I will be able to get the root view. And I will iterate over child views and change the value. But how can I listen to changes in activity.

Is there any other approach to this?

I know this is possible since many A / B testing libraries do this.

+3


source to share


2 answers


Here you go, see my answer on here

As you mentioned, the best way to trigger the connection to the activity lifecycle callbacks is through the AppContext. From there, you will have all the information you might need. Every time the activity switches, you will have an Activity object, and from there you can get a view of the root and apply the changes as needed.



I would advise against iterating over views! If you have a rootview, you can just do findViewId (textview C id) in that root view and you will grab your opinion!

+2


source


Since you are creating a library, you can expose a function that can be called after the onCreate of each action, which will give you a reference to the action. Once you have an activity, you can get its root view and do whatever magic you want to do.



This is the only other approach if you don't want to register LifeCycle callbacks for an activity. The app must go into your library at least at some point in time. Either you can make the application by hand (above approach), or you can override all lifecycle events of all activities (registering lifecycle callbacks).

+1


source







All Articles