0

i working on an android application, i have an api object that initialised to null in the main activity, i initilise it in another activity, and when i finish i call back my main activity like this:

            startActivity(new Intent(this, MainActivity.class));

when i come back to the main activity, it set up my api object to null; i don't know how i do to keep my api object set up, when i come back to the main i tried use static and protected but it's still not work

Would someone have a solution to avoid this problem?

1 Answers1

0

your mistake is that you start MainActivity again, you can just finish second activity.

if you want to send data from second activity to MainActivity you can use onActivityResult method

check this to read more link

AAV
  • 798
  • 1
  • 6
  • 23
  • 1
    typo. `onResault` => `onActivityResult` – Omkar76 Oct 22 '20 at 17:35
  • i try to finish but it still not work, it just close the web view i create in the second activity for login and load and don't want open the main one – brahimi haroun Oct 22 '20 at 17:39
  • can you edit post and give me some more code to help you? – AAV Oct 22 '20 at 17:42
  • you mean you have initialized it to null in the main activity and never used it anywhere in the code in main activity? if yes, why? if no, then you must have set it to some proper value somewhere along the way in the main activity. sharing your main activity code would help – MehranB Oct 22 '20 at 22:29