5

I'm using Twitter oAuth library in my application. Users are logging in with ther Twitter accounts.

In activity A, twitter login is available. When user logged in, I want to start activity B with no history. Here is my all stuff:

Firstly, Manifest.xml, so I set launchMode=singleTask as Twitter api requested:

<activity
    android:name=".A_Activity"
    android:label="@string/app_name"
    android:launchMode="singleTask"
    android:theme="@android:style/Theme.Black.NoTitleBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="my_twitter_scheme" />
    </intent-filter>
</activity>

Here is how I'm starting activity B:

Intent i = new Intent(A.this, B.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);

Note: I'm calling activity B over BroadcastReceiver instance.

When I logged in, my receivers starting activity B properly, but unfortunately when I pressed the back button, application turning back to activity A.

I suppose it's about launchMode and as I said, Twitter needs that option. What am I doing wrong? Any help or suggestion (maybe about Twitter) would be great.

Martin
  • 441
  • 3
  • 16

1 Answers1

2

I'm sure there should be more efficient ways to solve this issue but, I suggest something different.

Just call finish() method after you started an activity, so activity A would finish and when user pressed back button in activity B application returns home screen as you hope.

Also check twice your dialogs to avoid any exceptions, i.e check this question (and answers too) to understand what I meant.

Community
  • 1
  • 1
Ogulcan Orhan
  • 5,170
  • 6
  • 33
  • 49