Startactivity Within A Subclass Of Application
I have a little Android application in which I specify my application directly and do some application-wide setup in the ApplicationSubclass' onCreate, but I am getting the followi
Solution 1:
Ah! I figured out what I did, it's quite simple! I was setting the FLAG_ACTIVITY_NEW_TASK on the wrong intent! Silly me, I missed that Intent.createChooser(...,...) will return a new Intent, so you must set the flag on the chooser Intent rather than on the ACTION_SEND Intent.
Not all that confusing when you think about it, and I can't believe I overlooked that!
So if anyone ever does what I did, here you go:
publicvoidsendNotificationEmail(String emailBody) {
IntentemailIntent=newIntent(Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(Intent.EXTRA_EMAIL, notificationRecipients);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "MyAppName Error");
emailIntent.putExtra(Intent.EXTRA_TEXT, emailBody);
IntentemailChooser= Intent.createChooser(emailIntent, "An error has occurred! Send an error report?");
emailChooser.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(emailChooser);
} catch (ActivityNotFoundException e) {
// If there is nothing that can send a text/html MIME type
e.printStackTrace();
}
}
Solution 2:
I have launch an activity(to relogin the user when loss the session) from my class which subclass from Application as follow:
publicbooleanrelogin(Activity act) {
Intentintent=newIntent(act,ActivityLogin.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
act.finish();// here i finish my current activity
}
Post a Comment for "Startactivity Within A Subclass Of Application"