N
N
Nikolay Razumovsky2020-11-24 14:30:11
Java
Nikolay Razumovsky, 2020-11-24 14:30:11

How can the main activity get the intent data from the secondary?

There are two Activities. In an additional Activity, I have a timer ( android.os.CountDownTimer ). When I return to the main Activity, the timer stops and when I return back, it must be started from scratch. To return to the main Activity, I use the back
button . To fish out the desired data, I send it with .putExtra() - the remaining time and the timestamp. When I return to this Activity, I will simply compare the current time with the recorded time and make adjustments to the remaining time and start the timer from the right moment, making it appear that the timer has been running all this time.

@Override
    public void onBackPressed() {
        super.onBackPressed();
        Intent intent = new Intent(SecondActivity.this, FirstActivity.class);
        intent.putExtra("timeLeft", timeLeftMillis);
        intent.putExtra("timeSystem", System.currentTimeMillis());
        startActivity(intent);
    }

But I don't understand how can I get this data by the base Activity? Thank you in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2020-11-24
@frenneruruu

startActivityForResult + onActivityResult
UPD
The documentation recommends using the newer API from AndroidX.
This does not change the essence: you need to start the activity and get the result from it.
To put it bluntly, you don't have to. Use snippets. Several activities in the application are rather an exception, and you should clearly understand why there are several of them.

O
Oleg, 2020-11-24
@402d

Better think about how to make the timer count honestly.
for example through a service.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question