Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android startActivity from intent in service [duplicate]

i try to use intent in service but when i try this :

Intent intent_facebook = new Intent (this,MainUploadToYoutube.class);
intent_facebook.putExtra("vid", vid);
startActivity(intent_facebook);

got this error on logcat :

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

so i tried this from here :

android start activity from service

Intent  intent_facebook = new Intent(getBaseContext(), MainUploadToYoutube.class);
intent_facebook.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity( intent_facebook);

but this do nothing and i did not get error in logcat

what wrong ?

like image 894
idan Avatar asked Oct 21 '22 10:10

idan


1 Answers

Have you tried your own code (using this as context), but just add the flags as the error tells you?

Intent intent_facebook = new Intent (this, MainUploadToYoutube.class);
intent_facebook.putExtra("vid", vid);
intent_facebook.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent_facebook);
like image 181
Joffrey Avatar answered Oct 29 '22 18:10

Joffrey