Java Question Getting the class of a activity.

barx

Well-Known Member
Licensed User
Longtime User
Informatix - see edit to last post.

Also, kinda got it working now with your solution but there are still issues.

B4X:
      stackBuilder.addNextIntent(resultIntent);
      if (nTag != null)
         resultIntent.putExtra("Notification_Tag", nTag);         
         
      if(pActivity != null) {
         //stackBuilder.addParentStack(pActivity.getClass());

         //Informatix fix test
         String pn = BA.packageName;
         ComponentName cn = new ComponentName(pn, pn + "." + pActivity.toLowerCase((BA.cul)));
         BA.Log(cn.toString());
         stackBuilder.addParentStack(cn);
      }

using the above code it shows the parent first then goes back to the child 'popup', then exits the app. It should be the other way round. I re-checked the documentation I have been reading and it indeed puts the .addNextIntent after the .addParentStack. So I moved the addNextIntent down and then neither work. tapping the notification does nothing. Go figure....
 

Informatix

Expert
Licensed User
Longtime User
using the above code it shows the parent first then goes back to the child 'popup', then exits the app. It should be the other way round. I re-checked the documentation I have been reading and it indeed puts the .addNextIntent after the .addParentStack. So I moved the addNextIntent down and then neither work. tapping the notification does nothing. Go figure....

My limited skills can't help you more in this matter. I never tried to do that and I'm as puzzled as you are.
 

barx

Well-Known Member
Licensed User
Longtime User
My limited skills can't help you more in this matter. I never tried to do that and I'm as puzzled as you are.

No worries. Thanks for your help though. It's really helped.
 

barx

Well-Known Member
Licensed User
Longtime User
Hey Informatix, Can I have you 'limited skills' back for a few minutes please. I thought this was working, but I have now fixed a different issue and this kicks up a fuss now.

Java code:

B4X:
      if (pActivity != null) {
         String pn = BA.packageName;
         ComponentName cn = new ComponentName(pn, pn + "." + pActivity.toLowerCase((BA.cul)));
         stackBuilder.addParentStack(cn);
      }

Error when called from b4a

B4X:
** Activity (main) Create, isFirst = true **


main_activity_create (java line: 256)


java.lang.IllegalArgumentException: android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{barxdroid.nbtest/barxdroid.nbtest.Main2}
   at android.support.v4.app.TaskStackBuilder.addParentStack(TaskStackBuilder.java:236)
   at barxdroid.NotificationBuilder.NotificationBuilder.Notify(NotificationBuilder.java:256)
   at barxdroid.nbtest.main._activity_create(main.java:256)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
   at barxdroid.nbtest.main.afterFirstLayout(main.java:85)
   at barxdroid.nbtest.main.access$100(main.java:16)
   at barxdroid.nbtest.main$WaitForLayout.run(main.java:72)
   at android.os.Handler.handleCallback(Handler.java:605)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4575)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
   at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{barxdroid.nbtest/barxdroid.nbtest.Main2}
   at android.app.ApplicationPackageManager.getActivityInfo(ApplicationPackageManager.java:223)
   at android.support.v4.app.NavUtils.getParentActivityName(NavUtils.java:298)
   at android.support.v4.app.NavUtils.getParentActivityIntent(NavUtils.java:261)
   at android.support.v4.app.TaskStackBuilder.addParentStack(TaskStackBuilder.java:229)
   ... 17 more
java.lang.IllegalArgumentException: android.content.pm.PackageManager$NameNotFoundException: ComponentInfo{barxdroid.nbtest/barxdroid.nbtest.Main2}

I had this error before, but it was before adding your code. :(

Thanks
 

barx

Well-Known Member
Licensed User
Longtime User
It appears I have made an error in my manifest data. My apologies.

Now I get no error but also the parent still not getting shown

Is the return of the Component name the equivalent of passing the class.

I still can't help thinking that this Component Name is passing data like

B4X:
Setting Parent - ComponentInfo{barxdroid.nbtest/barxdroid.nbtest.main2}

Yet the example shows

B4X:
stackBuilder.addParentStack(ResultActivity.class);

So I'm expecting to see a main2.class or something.
 
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
Just managed to test on a jellybean device and it seems to be working. Maybe a version thing I.e. > ics.

Thanks for your help.
 
Top