문제

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