Showing black screen
<p>In my application i have to integrate twitter and linkedin integration in android. Everything is working fine. But problem is that when i click on my application twitter buttton to open twitter site here first comes black screen and then opens twitter webpage.</p>

<p>Now, here when without doing anything i press device back button it again shows me black screen and then again after pressing back button it comes to my activity.</p>

<pre><code>    if(arg0==TWITTER)
    {
        if(Webservice.isInternetOn(getApplicationContext()))
        {
            if (!Deja_Twitter_Utils.isAuthenticated(prefs)) 
            {
                Intent i=new Intent(this,Prepare_Request_Token.class);
                i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

                startActivity(i);
            }}
</code></pre>

<p>In above code where i have written i.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);It does not show me black screen but there is problem while posting message. It does not get authorization token. By removing this i am able to posting message. I am struggling for this issue for couple of days.</p>

<p>Any help would be appreciated.</p>

<p>Here is code that initiate twitter connection</p>

<p>public class Prepare_Request_Token extends Activity {</p>

<pre><code>final String TAG = getClass().getName();

private OAuthConsumer consumer; 
private OAuthProvider provider;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    try 
    {
        this.consumer = new CommonsHttpOAuthConsumer(Constants_Key.CONSUMER_KEY, Constants_Key.CONSUMER_SECRET);
        this.provider = new CommonsHttpOAuthProvider(Constants_Key.REQUEST_URL,Constants_Key.ACCESS_URL,Constants_Key.AUTHORIZE_URL);
    } 
    catch (Exception e)
    {
        Log.e(TAG, "Error creating consumer / provider",e);
    }

    Log.i(TAG, "Starting task to retrieve request token.");
    new OAuth_Request_TokenTask(this,consumer,provider).execute();
}

/**
 * Called when the OAuthRequestTokenTask finishes (user has authorized the request token).
 * The callback URL will be intercepted here.
 */

@Override
public void onNewIntent(Intent intent)
{
    System.out.println("**************************on NEW INTENT****");
    super.onNewIntent(intent); 
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
final Uri uri = intent.getData();
if (uri != null &amp;&amp; uri.getScheme().equals(Constants_Key.OAUTH_CALLBACK_SCHEME)) {
        Log.i(TAG, "Callback received : " + uri);
        Log.i(TAG, "Retrieving Access Token");
        new RetrieveAccessTokenTask(this,consumer,provider,prefs).execute(uri);
        finish();   
    }
}

public class RetrieveAccessTokenTask extends AsyncTask&lt;Uri, Void, Void&gt; {

    private Context context;
    private OAuthProvider provider;
    private OAuthConsumer consumer;
    private SharedPreferences prefs;

    public RetrieveAccessTokenTask(Context context, OAuthConsumer consumer,OAuthProvider provider, SharedPreferences prefs) {
        this.context = context;
        this.consumer = consumer;
        this.provider = provider;
        this.prefs=prefs;
    }


    /**
     * Retrieve the oauth_verifier, and store the oauth and oauth_token_secret 
     * for future API calls.
     */
    @Override
    protected Void doInBackground(Uri...params) {
        final Uri uri = params[0];
        final String oauth_verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);

        try {
            provider.retrieveAccessToken(consumer, oauth_verifier);

            final Editor edit = prefs.edit();
            edit.putString(OAuth.OAUTH_TOKEN, consumer.getToken());
            edit.putString(OAuth.OAUTH_TOKEN_SECRET, consumer.getTokenSecret());
            edit.commit();

            String token = prefs.getString(OAuth.OAUTH_TOKEN, "");
            String secret = prefs.getString(OAuth.OAUTH_TOKEN_SECRET, "");

            System.out.println("*************TOKEN INPREPARE*****"+token);
            consumer.setTokenWithSecret(token, secret);
            //context.startActivity(new Intent(context,Twitter_Update.class));

            //executeAfterAccessTokenRetrieval();

            Log.i(TAG, "OAuth - Access Token Retrieved");

        } catch (Exception e) {
            Log.e(TAG, "OAuth - Access Token Retrieval Error", e);
        }

        return null;
    }


    private void executeAfterAccessTokenRetrieval()
    {
        String msg = getIntent().getExtras().getString("tweet_msg");
</code></pre>

<p>System.out.println("<strong><em>*</em>**<em>*</em>***</strong><em>executeAfterAccessTokenRetrieval()<strong></em>"+msg);
            try
            {
                System.out.println("<em>*</em>**<em>*</em>**<em>*</em></strong><em>sendTweet()</em>**"+msg);
                Deja_Twitter_Utils.sendTweet(prefs, msg);
            } 
            catch (Exception e) 
            {
                Log.e(TAG, "OAuth - Error sending to Twitter", e);
            }
        }
    }   </p>

<pre><code>public class OAuth_Request_TokenTask extends AsyncTask&lt;Void, Void, Void&gt; {

    final String TAG = getClass().getName();
    private Context context;
    private OAuthProvider provider;
    private OAuthConsumer consumer;

    /**
     * 
     * We pass the OAuth consumer and provider.
     * 
     * @param   context
     *          Required to be able to start the intent to launch the browser.
     * @param   provider
     *          The OAuthProvider object
     * @param   consumer
     *          The OAuthConsumer object
     */
    private final ProgressDialog dialog = new ProgressDialog(getDialogContext());
    protected void onPreExecute() 
    {
        this.dialog.setMessage("Please Wait..");
        this.dialog.show();

    }
    public OAuth_Request_TokenTask(Context context,OAuthConsumer consumer,OAuthProvider provider) 
    {
        this.context = context;
        this.consumer = consumer;
        this.provider = provider;
    }

    /**
     * 
     * Retrieve the OAuth Request Token and present a browser to the user to authorize the token.
     * 
     */
    @Override
    protected Void doInBackground(Void... params) 
    {

        try {
            Log.i(TAG, "Retrieving request token from Google servers");
            final String url = provider.retrieveRequestToken(consumer, Constants_Key.OAUTH_CALLBACK_URL);
            Log.i(TAG, "Popping a browser with the authorize URL : " + url);

            /*************************************************************************/

            System.out.println("*************************IN SHOW DIALOGUE************"+url);


            /*************************************************************************/
            //new Twitter_DIal(context, url,listener).show();
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND);
            context.startActivity(intent);


            //finish();
        } catch (Exception e) {
            Log.e(TAG, "Error during OAUth retrieve request token", e);
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void unused)
    {
            this.dialog.dismiss();   
    }


}
private Context getDialogContext() 
{
    Context context;
    if (getParent() != null) context = getParent();
    else context = this;
    return context;
}
@Override
public void onBackPressed() 
{
    System.out.println("****************onBackPressed() prepare request token***");
    finish();
    return;
}
</code></pre>
