adam dewhurst adam dewhurst - 6 months ago 8
Android Question

If Statement cant be recognised?

I'm having an issue with my if statement in my app development code

if (Intent.resolveActivity(getPackageManager())!=null)
{
startActivity(intent);
}


the error is brought up on the resolveActivity section which the error is as follows : Non-static method 'resolveActivity(android.content.pm.PackageManager)' cannot be referenced from a static context .
What does this mean and how do I resolve it

Thanks

Answer

The function "resolveActivity" is non-static. You need an Intent-Instance to call that function. If you are in an Activity you can use

if (getIntent().resolveActivity(getPackageManager())!=null)
{
    startActivity(intent);
}