Próbuję rozpocząć działanie wewnątrz klasy usług. Mam następujący kod:Wywołanie funkcji startActivity() z zewnątrz kontekstu działania wymaga FLAG_ACTIVITY_NEW_TASK
public class SendLinkService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Bundle bundle = intent.getExtras();
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, bundle.getString("URL"));
getApplicationContext().startActivity(Intent.createChooser(shareIntent, "Share via"));
return super.onStartCommand(intent, flags, startId);
}
}
To daje następujący wyjątek na linię onStartCommand():
getApplicationContext().startActivity(Intent.createChooser(shareIntent, "Share via"));
"Próbuję rozpocząć działanie wewnątrz klasy usług" - dlaczego ta usługa istnieje? Jaką wartość ten kod dodaje, będąc w usłudze, a nie będąc w działaniu? – CommonsWare