I am working on an option in an app to share a download link with people. Below is what I have. What is the issue?
public void onClick(View v) {
Intent intent = new Intent();
boolean start = true;
String test = "google.com";
switch (v.getId()) {
(...)
case R.id.share:
start = false;
Intent send = new Intent();
send.setAction(Intent.ACTION_SEND);
send.putExtra(Intent.EXTRA_TEXT, test);
send.setType("text/plain");
startActivity(send);
break;
}
if (start)
startActivity(intent); //line 135
}
At the end of the switch, if start is false it will not perform startActivity(), since it is doing so inside the case for share. However, when I clock on this in the app i get the following error...
02-19 11:55:01.630: E/AndroidRuntime(27279): android.content.ActivityNotFoundException: No Activity found to handle Intent { }
And this references line 135, which would be the second "startActivity()". anyone have any clue what's going on?
Intent isn't set, as you send Intent send
.
Why do you have line 135 at all since you already send the email in startActivity(send)
?
Change line 135 from
startActivity(intent); //line 135
to
startActivity(send); //line 135
When you get to the if(start) block, the intent was never correctly initialized with the action and other arguments. I don't know exactly what you are trying to accomplish, but you need something like this:
if (start) {
// Set appropriate parameters here...
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, test);
intent.setType("text/plain");
startActivity(intent); //line 135
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.