3

I want to create project that reacts to OnCreate() method. So, for example, I have activity

public class MainActivity extends Activity
{
 @Override
    public void onCreate(Bundle savedInstanceState)
    {
    //do something
    }
}

And i want my AspectJ class to do something before and after OnCreate method call.

public aspect onCreate
{

    pointcut captureOnCreate() : (execution(* onCreate(Bundle)));

    before(): captureOnCreate()
    {

        System.out.println("Aspect BEFORE called");
    }

    after(): captureOnCreate()
    {


        System.out.println("Aspect AFTER called");


    }
}

I tried to convert project to AspectJ and run it as Android application project, but it doesn't work. What is wrong?

SOLVED

Solved it myself. In Eclipse AspectJ tools -> Inpath -> Add External JARs and link it to aspectjrt.jar file.

And executoin looks like that:
execution(* onCreate(*))&& !within(com.xxx.automation.onCreate);

Romans Stepanovs
  • 847
  • 1
  • 7
  • 10

0 Answers0