Basically I agree with @pskink's comments: If you can just extend a class and override its methods this is preferable to using "heavy artillery" such as AspectJ. From what I understand you want to manipulate another app for which you do not have the source code and into which you cannot inject your subclass with the overridden method. If this is correct, I do understand the need for AspectJ. So here is the answer to your question:
Well, I do not use Android and am too lazy to download the full Android JDK just in order to demonstrate the solution, but I just created a fake example.
API base class:
package org.base.api;
public class Activity {
protected void onCreate(Object obj) {
System.out.println("onCreate default implementation");
}
public boolean onCreateOptionsMenu(Object obj) {
System.out.println("onCreateOptionsMenu default implementation");
return false;
}
}
Driver application:
As I said, I am assuming the app to be be commercial, so you cannot change its behaviour by conventional OOP means. The app overrides one API method, but not the one you want.
package com.commercial.app;
import org.base.api.Activity;
public class CommercialAppActivity extends Activity {
@Override
protected void onCreate (Object obj) {
System.out.println("onCreate implementation overridden by commercial app");
}
public static void main(String[] args) {
System.out.println("Starting commercial app");
CommercialAppActivity activity = new CommercialAppActivity();
activity.onCreate(null);
activity.onCreateOptionsMenu("menu");
System.out.println("Stopping commercial app");
}
}
Sample output:
Starting commercial app
onCreate implementation overridden by commercial app
onCreateOptionsMenu default implementation
Stopping commercial app
Aspect introducing desired method via ITD (inter-type definition):
package de.scrum_master.aspect;
import com.commercial.app.CommercialAppActivity;
public aspect AppManipulatorAspect {
public boolean CommercialAppActivity.onCreateOptionsMenu(Object obj) {
System.out.println("onCreateOptionsMenu implementation overridden by aspect");
return false;
}
}
Sample output with spect:
Starting commercial app
onCreate implementation overridden by commercial app
onCreateOptionsMenu implementation overridden by aspect
Stopping commercial app
Tadaa! It should be straightforward to transfer this to your situation.