我是Aspectj的新手。我的问题是我想在Android中获取我的MainApp的Activity(或Context)而不修改我的原始代码。我有这个:
public class SensorTestActivity extends Activity implements SensorEventListener {
private SensorManager sensorManager;
private boolean color = false;
private View view;
private long lastUpdate;
//public static Context context;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sensor_test);
view = findViewById(R.id.textView);
view.setBackgroundColor(Color.GREEN);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
lastUpdate = System.currentTimeMillis();
//context=this;
}
现在使用Aspectj,我想要做的是添加两个注释行并获取Context并使用它。类似的东西:
public aspect Trace extends Application{
private static Context SensorTestActivity.mContext;
pointcut inicio(Bundle bundle) : execution(* ..onCreate*(..)) && args(bundle);
void around(Bundle bundle): inicio(bundle){
//System.out.println("I'm in onCreate");
SensorTestActivity.mContext= this;
proceed(bundle);
}
问题是我不能使用“这个”。如果你知道如何做到这一点,或者如果有另一种方法在.aj文件中获取Context,我将非常感激。谢谢!