When I call startActivityForResult (or startActivity) the "onCreate" of the MainActivity is being called even before the new activity is created. It doesn't happen with other intents.

This is the code inside click handler of a button in a listview that has an adapter (inside a fragment inside a tab of SherlockActionBar):

            ((MainActivity)context).setVideoId(v.getTag().toString());
            Intent videoIntent = YouTubeStandalonePlayer.createVideoIntent((Activity) context, "AIzaSyC1sF6kq9hHGrQvRSiU8Ks5iYfVCbdg7zA", v.getTag().toString(), 0, true, false);
            ((Activity)context).startActivityForResult(videoIntent, 12);

and this is the constructor of the adapter:

    public ItemAdapter(Context c, int textViewResourceId) {
    super(c, textViewResourceId);
    this.layoutResourceId = textViewResourceId;
    this.context = c;
有帮助吗?

解决方案

It's happened because activity change orientation. Add this in the manifest:

<activity
android:configChanges="orientation|screenSize|keyboardHidden"
...
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top