mercredi 20 mai 2015

Calling StartActivity() from outside of Activity not working for me

Hello I am trying to call StartActivity() from outside an activity & this is my method I am using and its not giving me any errors, but when I run the project and click on the button it says "unfortunately my app has stopped running" and in the log cat it gives me this

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

which I dont understand since I already have "sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);" can any body please help me with this any help would be greatly appreciated I have been stuck on this for a few days now

public void shareIt() {

        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        sharingIntent.setType("text/plain");
        String shareBody = "Here is the share content body";


        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);



        AndroidGame.getContext().startActivity(Intent.createChooser(sharingIntent, "Share via"));

    }

Aucun commentaire:

Enregistrer un commentaire