0

Can I make an Intent in application to change from one activity to other without bringing to foreground. For Example activity A is in foreground and activity B is in background . I have to change activity B to Activity C without bringing to foreground.

Sindujan Nirmalan
  • 470
  • 1
  • 8
  • 18
  • Would it be ok if you put the app from background to foreground and then seeing the desired activity? because there will be a solution for that – Bita Mirshafiee Jun 28 '20 at 18:27
  • I have to do this in background without bringing to foreground. But the app is in foreground and particular activity is only in background. Do you have solution??? – Sindujan Nirmalan Jun 28 '20 at 18:31

1 Answers1

1

The safest bet would be to start using fragments. Could you describe your problem a little bit more in depth. I might be able to help you then. I, myself, have never encountered such a situation since my activities extend my use-case specific custom AppCompatActivity classes. I try to offload most of my work to other classes. For example "MathPlus", "ViewUtils", "ThemeHelper" and numerous other. It's a mess. But my mess. And I admire it every single day.

  • yeah sure, if home button is pressed while using the application, i have to clear all the activities in my stack.(That work is done) and the login screen is only one activity in the stack. but the whole change should be done in the background. because once home button is pressed my app should go to background it should not come to foreground to make that intent. Same type of thing i have seen in some password manager application. when home button is pressed app went to background. if we open the app again it only shows the login page. – Sindujan Nirmalan Jun 28 '20 at 19:23
  • I suppose you could override a method like onResume() to check if the app needs to be restarted i.e. send you back to the login screen. I'd like to point out Mike Penz's solution [here](https://stackoverflow.com/questions/6609414/how-do-i-programmatically-restart-an-android-app). I haven't tested if his solution even works but by now you should have gotten the gist of it. If you have any more questions. I am more than happy to clarify. – Mišo Barišić Jun 28 '20 at 19:35
  • Checking inside onResume works, but application try to log out because user not to see the UI.(UI has some sensitive information). if we tap switch button(next to home button) it is visible.That is why i am asking to change the activity in background. Onresume works when app comes to foreground. Until it comes to foreground no changes happens. Thank you so much for the support. ill check with Mike Pemz' solution – Sindujan Nirmalan Jun 28 '20 at 20:13
  • There is a solution. Hide the information by overriding onPause() and onResume(). Hide the data with onPause - triggered when app goes to background. – Mišo Barišić Jun 28 '20 at 20:16
  • Yep Finally got an idea to finish my work. Thank you for the support. It is very easy solution thanks alot – Sindujan Nirmalan Jun 28 '20 at 20:26