0

So I am trying to start another app from within my app, but on certain devices it is coming up with this error Fatal Exception: java.lang.NullPointerException Attempt to invoke virtual method 'int android.content.Intent.getFlags()' on a null object reference and before someone flags this, I already looked at https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it, but I am not understanding how this can bring NullPointerException only on certain devices, even with a check null in there. Is there some other way I should be doing this to avoid it? Would a try & catch be a better method to avoid this?

Here is my code for starting the other activity:

public void startApp(final Context c, final String appName)
{
    final Intent b = c.getPackageManager().getLaunchIntentForPackage(appName);

    if (appName.equals("myapp"))
    {
                Intent intent = new Intent();
                intent.setClass(c, Dashboard.class);
                intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
                c.startActivity(intent);
    }else {
                if (b != null) {
                b.setFlags(FLAG_ACTIVITY_NEW_TASK);
                c.startActivity(b);
                }
    }
}
user2101081
  • 445
  • 5
  • 22

0 Answers0