Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Check for target activity available or not

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 261
    Comment on it

    We know that implicit intents are used to perform an action that your application can't but others can do.

    Like to send some sms we uses this intent :

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_SEND);
    intent.putExtra(Intent.EXTRA_TEXT, textMessage);
    intent.setType(HTTP.PLAIN_TEXT_TYPE);
    startActivity(sendIntent);
    

    But do you know this can crash your app if your device doesn't have target activity to send sms.

    To solve this we use resolveActivity method like this :

      if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
     } else{
       //Activity not found
     }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: