Android instrumentation.execStartActivity parameters

一笑奈何 提交于 2019-12-11 04:24:57

问题


Having a bit of trouble. I'm trying to start an activity using another activity and need to get the 7 parameters of the execStartActivity method in the instrumentation.java class.

From what I can tell the method is as follows:

    execStartActivity(
    Context who, IBinder contextThread, IBinder token, Activity target,
    Intent intent, int requestCode, Bundle options) {

Suppose my starting activity is called MainActivity. Obviously the who parameter, as stated in documentation, is my base activity so it would be called by getApplicationContext(). The next parameter is where I'm getting stuck. How can I get a contextThread for IBinder? I've tried:

    Looper.getMainLooper().getThread() 

and

    getApplicationContext().getMainLooper().getThread()

Also for the IBinder token is that just some arbitrary string you assign as a "token" value to represent your starting activity? The next param is your main class's starting activity, but is the Intent intent supposed to be the something like:

    new Intent(this, SecondClass.class)? 

What if I was trying to load another application?

Would the intent be the packagename such as:

    ("com.example.application2", null)?

I just put -1 for the request code, but I'm also stuck on the bundle option (I just left it empty).

Can we automatically get these parameters? Should I not be trying to manually use instrumentation?

Any help would be appreciated.

来源:https://stackoverflow.com/questions/42100863/android-instrumentation-execstartactivity-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!