1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| public class MainActivity extends AppCompatActivity{ protected void onCreate(Bundle savedInstanceState) { super.onCreate(saveInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.mBtn).setOnClickListener(new OnClickListener(){ public void onClick(View v){ startActivity(new Intent(MainActivity.this, MainActivity.class)); } }); try{ Field InstrumentationField = Activity.Class.getDeclaredField("mInstrumentation"); InstrumentationField.setAccessible(true); Instrumentation mInstrumentation = InstrumentationField.get(this); mInstrumentation = new ExtInstrumentation(mInstrumentation); mInstrumentation.set(this, mInstrumentation); } catch(Exception e){ } } class ExtInstrumentation extends Instrumentation{ private Instrumentation target; public ExtInstrumentation(Instrumentation target){ this.target = target; } public ActivityResult execStartActivity( Context who, IBinder contextThread, IBinder token, Activity target, Intent intent, int requestCode, Bundle options) {
Log.d("TAG", "\n执行了startActivity, 参数如下: \n" + "who = [" + who + "], " + "\ncontextThread = [" + contextThread + "], \ntoken = [" + token + "], " + "\ntarget = [" + target + "], \nintent = [" + intent + "], \nrequestCode = [" + requestCode + "], \noptions = [" + options + "]");
try { Method execStartActivity = Instrumentation.class.getDeclaredMethod( "execStartActivity", Context.class, IBinder.class, IBinder.class, Activity.class, Intent.class, int.class, Bundle.class); execStartActivity.setAccessible(true); return (ActivityResult) execStartActivity.invoke(target, who, contextThread, token, target, intent, requestCode, options); } catch (Exception e) { throw new RuntimeException("do not support!!! pls adapt it"); } } } }
|