1

Basically, I have an activity which contains the code for a Video conferencing app. And I need to keep that in the background. So that when the user presses a button, I create a FloatingViewService, and send from my activity, the data to that FloatingViewService. And I can for example (This works), start a new intent, and use it to navigate through my app, while my previous activity is still working, and sending the data to the FloatingViewService. Now my problem is that I don't want to start a random activity, but I want to go back to the previous activity, before starting the call. When I start my call, I do it like this:

   Intent intent = new Intent(HomeActivity.this, InCallActivity.class);
    intent.putExtra("url", "url");
    intent.putExtra("test", false);
    startActivity(intent);

And note! After the second activity is created, if I call finish, it will take me to my HomeActivity. Which is awesome. BUT I don't want to finish, I simply just want to go to the activity from which my class is being called.

I tried with: moveTaskToBack(true); but it sends the app to the home screen. Also I made this code:

 ActivityManager m = (ActivityManager) getSystemService(ACTIVITY_SERVICE );
    List<ActivityManager.RunningTaskInfo> runningTaskInfoList =  m.getRunningTasks(10);
    Iterator<ActivityManager.RunningTaskInfo> itr = runningTaskInfoList.iterator();
    while(itr.hasNext()){
        ActivityManager.RunningTaskInfo runningTaskInfo = (ActivityManager.RunningTaskInfo)itr.next();
        int id = runningTaskInfo.id;
        CharSequence desc= runningTaskInfo.description;
        int numOfActivities = runningTaskInfo.numActivities;
        String topActivity = runningTaskInfo.topActivity.getShortClassName();
        Log.i("","top activity: " + topActivity);
    }

Thinking that I can reinstate the activity from the backstack, using the FLAG_ACTIVITY_REORDER_TO_FRONT

BUT, I don't get my activity back, why is that? All I get is:

12-06 13:17:54.213: D/HeartRateApplication(3168): top activity: com.vidyo.vidyocore.activities.WebViewActivity
12-06 13:17:54.213: D/HeartRateApplication(3168): top activity: com.google.android.launcher.GEL

But if I do finish, clearly my HomeActivity is there, because it takes me back to it. Why don't I get it in my list from the running activities? And how can I fix this?

EDIT:

There was a comment that said that I should start the activity with a intent. So I feel maybe I was not clear enough. I cannot start an intent to a default Activity. There is a chance that this InCallActivity will be called from multiple activities. Hence I need to know what activity was before it, so I can call an intent to that activity, WITH like I said FLAG_ACTIVITY_REORDER_TO_FRONT Hence the logic to use the runningTaskInfo but that doesn't not provide me with the whole backstack. Is there another way to get the backstack, so I can actually know whay activity to start?

rosu alin
  • 5,674
  • 11
  • 69
  • 150

1 Answers1

1

Start the activity using Intent.FLAG_ACTIVITY_CLEAR_TOP

Also you can refer this

String Activity name= getIntent().getStringExtra("mActivityName");

use this to track your activity flow and name.

Aqua 4
  • 771
  • 2
  • 9
  • 26
  • let me say it like this. I want to start Activity B, and then go back to the activity that started it. I may have 3 cases: A->B and need B->A, A'->B and then B->A' , A"->B and need B->A". How can I know in B which class started it, and to start the intent towards THAT exact class. PS: This will be a library, so I have access to the code in class B, but can't modify classes A, A', A" which will call the intent to B. And that is why I try to use the backstack. MY real question is why the backstack doesn't return activity A in the list, if clearly it is there (finish takes me to A resumed) – rosu alin Dec 06 '17 at 12:49
  • now this is getting complicated but a very simple solution to your problem would be to add a TAG along with intent.putExtra(ACT name) so that you will be able to keep track of activity flow............................................... Eg: String mAdvId=getIntent().getStringExtra("mADV"); String mCliId=getIntent().getStringExtra("mCLI"); String mCasStat=getIntent().getStringExtra("mCAS"); – Aqua 4 Dec 06 '17 at 12:56
  • I'll accept this answer, because that is what I'm going to do, just force via the documentation the users to send the name of the activity and then when it is needed make the intent to that – rosu alin Dec 06 '17 at 13:10