Consider having these two codes:
Code 1:
Uri uri = Uri.parse(url);
intent.setDataAndType(uri, "audio/*");
Code 2:
intent.setDataAndType( Uri.parse(url), "audio/*");
Which one gives better performance?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Second one is more resource-efficient! However if you reuse the
urivariable you shall go with the first one, to keep the variable persistent. The difference is pretty much minor as the snippet of code will only need few resources to run so you will not have much of a gain. Consider that the garbage collector will get the uri object as soon as it is not referenced again. All in all, pick the second if you are tight with resources, though the difference is too small to consider, but the first one gives you a reusable object, which you shall consider if you need it again.