How do I wait for a response in TwitterKit Android SDK's BroadcastReceiver?

I have an activity that posts tweets using Twitter's TweetComposer SDK, available here, my code follows the tutorial, a receiver is added to the Android Manifest file as follows:

<receiver
        android:name=".MyResultReceiver"
        android:exported="false">
        <intent-filter>
            <action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_SUCCESS" />
            <action android:name="com.twitter.sdk.android.tweetcomposer.UPLOAD_FAILURE" />
            <action android:name="com.twitter.sdk.android.tweetcomposer.TWEET_COMPOSE_CANCEL" />
        </intent-filter>
</receiver>

And the Receiver is instantiated within the activity as this:

BroadcastReceiver broadcastReceiver =  new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle b = intent.getExtras();
        String message = b != null ? b.getString("tweetid") : null;
    }
};

As you see, in that receiver I try to gather the id from the tweet that has just been posted. The issue is that I cannot use this id until it is received via the BroadcastReceiver. Which happens only when the upload of the tweet has been completed.

On slower connections, posting tweets with pictures takes longer than it takes to go from the composer activity to the activity that called the composer in the first place.

I tried calling a ProgressDialog (even though I know it is now deprecated) from the onResume() method but I kept getting this error:

Unable to resume activity {}: android.view.WindowManager$BadTokenException: Unable to add window -- token null for displayid = 0 is not valid; is your activity running?

I need to find a way to bring up a dialog or another way to avoid the user leaving the activity before I receive the id of the tweet sent.

Thanks in advance for your help.

Upvotes: 0

Views: 111

Answers (0)

Related Questions