5

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 ?

Community
  • 1
  • 1
idan
  • 1,508
  • 5
  • 29
  • 60

3 Answers3

3

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);
Joffrey
  • 32,348
  • 6
  • 68
  • 100
0

this may help

in Service class you get context and initialize with Context mContext

 Intent intent = new Intent(mContext,MainUploadToYoutube.class);   
 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
 ((Activity)mContext).startActivity(intent);
Ankitkumar Makwana
  • 3,475
  • 3
  • 19
  • 45
  • 1
    Context mContext = getBaseContext(); Intent intent2 = new Intent(mContext,MainUploadToYoutube.class); intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); ((Activity)mContext).startActivity(intent2); i try this but mcontext could not cast to activity – idan May 13 '13 at 11:16
0

There is nothing wrong with your code. It should work. Your problem is something else. Make sure MainUploadToYoutube activity is defined in the manifest and app may not crash once this activity is lunched.

Gani
  • 3
  • 2
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216