// "notificationText" is the String with the notification text to send to main activity
BA.Log("MSG:" + notificationText );
// Locate the activity
ActivityManager activityManager = (ActivityManager) context.getSystemService("activity");
List<ActivityManager.RunningTaskInfo> taskInfo = activityManager.getRunningTasks(1);
String currentTopActivity = taskInfo.get(0).topActivity.getClassName();
// This is the top activity
BA.Log("MSG ACTIVITY:" + currentTopActivity );
// Try to instance the object to call the remote method
try {
Class myClass = Class.forName(currentTopActivity);
Activity act;
act = (Activity) myClass.newInstance();
//Get the list of possible methods held in this object.
Method[] methods = myClass.getMethods();
// iterate through them
//for (Method method : methods) {
// BA.Log("" + this.getClass().getName() + "--------------------------");
// BA.Log("" + this.getClass().getName()+ "Method: " + method.getName());
// BA.Log("" + this.getClass().getName()+ "Return Type: " + method.getReturnType());
// BA.Log("" + this.getClass().getName()+ "Class: " + method.getClass());
// BA.Log("" + this.getClass().getName()+ "Declaring Class: " + method.getDeclaringClass());
//}
// BA.Log("" + this.getClass().getName()+"--------------------------");
// But I now exactly the method I want
Method setNameMethod = myClass.getMethod("_recebeu_mensagem", String.class);
// Now call the method of main activity
setNameMethod.invoke(act, notificationText); // pass arg
}
catch( Exception e){
BA.Log("ERRO!!! = " + e);
}