If app C has the GET_TASKS permission, you can see what the most recent task was.
ActivityManager man = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RecentTaskInfo> list = man.getRecentTasks(1, 0);
//You might want to check if(list.size() > 0)
Intent caller = list.get(0).baseIntent;
//look at caller.getComponent() for the package and class
In my testing, I found that baseIntent on the top of the recent task stack was the most reliable identifier. There is more discussion about why you might not want to do this in https://stackoverflow.com/a/12376775/1135142
I suppose if you have any control over A and B, you could have them call for a result as mentioned already.