0

My understanding is that the view of another activity cannot be returned. To flag when com.android.settings > Bluetooth is the current view, am I on the right track with the code below?

ActivityManager am = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE);
List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(30); 
ComponentName componentInfo = null;
String componentInfo_getPackageName;

for(int i = 0;i<taskInfo.size();i++)
{
  componentInfo = taskInfo.get(i).topActivity;
  componentInfo_getPackageName = componentInfo.getPackageName();

  if (componentInfo_getPackageName.contains("settings")){
    Class<Object> clazz = null;
    componentInfo.getClass().asSubclass(clazz);
  }   
}
A--C
  • 36,351
  • 10
  • 106
  • 92
user3002933
  • 21
  • 1
  • 4
  • componentInfo is an instance of `ComponentName`, and an `Activity` is *never* a `ComponentName`. Also, you're passing `null` to `asSubclass()`, which probably throws a `NullPointerException`. The questions really are, what are you trying to achieve and why? – A--C Nov 18 '13 at 01:19
  • Thank you. My objective is to display a warning, when children are about to change Blue Tooth settings for example, while not interrupting changes to Date Time settings and the like. – user3002933 Nov 19 '13 at 23:55
  • Considering that normal, Android won't allow you to access another process directly, looking through the ActivityInfo would be the best you can do. – A--C Nov 21 '13 at 02:05
  • If I change the code above to: if (componentInfo.toString().toLowerCase().contains("subsettings")){ } If http://stackoverflow.com/questions/1457803/how-do-i-access-androidlabel-for-an-activity is correct, how do I retrieve the ComponentName ? – user3002933 Nov 21 '13 at 19:31
  • Your `componentInfo` variable is a `ComponentName`,so it is alrady retrieved (you really *should* rename your variables because `ComponentInfo` is another class, making your current name choice misleading. – A--C Nov 22 '13 at 01:17
  • Am I on the right track with code below? If so, please direct me to an example for loadXmlMetaData . if (componentName.toString().toLowerCase().contains("subsettings")){ PackageManager pm = getPackageManager(); try { ActivityInfo ai = pm.getActivityInfo(componentName, PackageManager.GET_ACTIVITIES|PackageManager.GET_META_DATA|PackageManager.GET_INTENT_FILTERS); XmlResourceParser xml = ai.loadXmlMetaData(pm, componentName.toString()); – user3002933 Nov 27 '13 at 20:57

0 Answers0