Answer the question
In order to leave comments, you need to log in
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);
}
Answer the question
In order to leave comments, you need to log in
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question