Android instrumentation.execStartActivity paramete

2019-07-24 12:23发布

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.

0条回答
登录 后发表回答