Browse Source

Fixed strange activity bug.

Alexander Brakowski 7 years ago
parent
commit
9f0bf27ffe

+ 1 - 0
AndroidManifest.xml

@@ -57,6 +57,7 @@
         <activity
             android:name=".ui.activity.MainActivity"
             android:configChanges="keyboardHidden|orientation|screenSize"
+            android:launchMode="singleInstance"
             android:label="@string/app_name"
             android:screenOrientation="portrait" >
             <intent-filter>

+ 12 - 3
src/de/tudarmstadt/informatik/hostage/Hostage.java

@@ -419,10 +419,10 @@ public class Hostage extends Service {
 		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
 		stackBuilder.addParentStack(MainActivity.class);
 		Intent intent = MainActivity.getInstance().getIntent();
-		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
+		intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
 		intent.setAction("SHOW_HOME");
 		stackBuilder.addNextIntent(intent);
-		PendingIntent resultPendingIntent = PendingIntent.getActivity(MainActivity.context, 0, intent, 0);
+		PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
 		builder.setContentIntent(resultPendingIntent);
 		if (defaultPref.getBoolean("pref_vibration", false)) {
 			builder.setVibrate(new long[] { 100, 200, 100, 200 });
@@ -486,7 +486,9 @@ public class Hostage extends Service {
 				bssidSeen = true;
 			}
 		}
+
 		builder = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.app_name)).setWhen(System.currentTimeMillis());
+
 		if (!listening) {
 			builder.setSmallIcon(R.drawable.ic_launcher);
 			builder.setContentText(getString(R.string.hostage_not_monitoring));
@@ -500,16 +502,23 @@ public class Hostage extends Service {
 			builder.setSmallIcon(R.drawable.ic_service_green);
 			builder.setContentText(getString(R.string.hostage_no_threat));
 		}
+
 		Intent launchIntent = new Intent(getApplicationContext(), MainActivity.class);
 		TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
 		stackBuilder.addParentStack(MainActivity.class);
+
 		Intent intent = MainActivity.getInstance().getIntent();
-		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
+        intent.addCategory(Intent.ACTION_MAIN);
+        intent.addCategory(Intent.CATEGORY_LAUNCHER);
+        intent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+		//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
 		intent.setAction("SHOW_HOME");
 		stackBuilder.addNextIntent(intent);
+
 		PendingIntent resultPendingIntent = PendingIntent.getActivity(MainActivity.context, 0, intent, 0); //stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
 		builder.setContentIntent(resultPendingIntent);
 		builder.setOngoing(true);
+
 		NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
 		mNotificationManager.notify(1, builder.build());
 	}

+ 9 - 9
src/de/tudarmstadt/informatik/hostage/ui/activity/MainActivity.java

@@ -156,7 +156,7 @@ public class MainActivity extends Activity {
 	/**
 	 * Holds the root fragment for our hierarchical fragment navigation
 	 */
-	private Fragment mRootFragment;
+    private Fragment mRootFragment;
 
 	/**
 	 * Indicates if the warning, that the application will be closed, when pressing back again
@@ -216,8 +216,7 @@ public class MainActivity extends Activity {
 	@Override
 	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
-
-		// make the main activity an singleton
+        // make the main activity an singleton
 		sInstance = this;
 
 		// sets the static context reference to the application context
@@ -315,10 +314,10 @@ public class MainActivity extends Activity {
 		}
 
 
-		if (savedInstanceState == null) {
-			// on first time display view for first nav item
-			displayView(0);
-		} else {
+        if (savedInstanceState == null) {
+            // on first time display view for first nav item
+            displayView(0);
+        } else {
             mDisplayedFragmentIndex = savedInstanceState.getInt("mDisplayedFragmentIndex");
             mDisplayedFragment = getFragmentManager().getFragment(savedInstanceState, "mDisplayedFragment");
             mRootFragment = getFragmentManager().getFragment(savedInstanceState, "mRootFragment");
@@ -331,15 +330,16 @@ public class MainActivity extends Activity {
 
             injectFragment(mDisplayedFragment);
         }
+
 	}
 
     @Override
     protected void onSaveInstanceState(Bundle outState){
-        super.onSaveInstanceState(outState);
-
         outState.putInt("mDisplayedFragmentIndex", mDisplayedFragmentIndex);
         getFragmentManager().putFragment(outState, "mRootFragment", mRootFragment);
         getFragmentManager().putFragment(outState, "mDisplayedFragment", mDisplayedFragment);
+
+        super.onSaveInstanceState(outState);
     }
 
 	/**