A
A
Andrew2019-09-25 01:24:08
Java
Andrew, 2019-09-25 01:24:08

Data from the Popup to the calling Activity. How to properly organize?

I have an Activity0 that creates a popup window with an EditText and OK and CANCEL buttons. On the OnClick event of the OK button, you need to transfer the data in the EditText to Activity0.
I wouldn't have any trouble with this if I didn't move the actual creation of the Popup into a separate ToggleValues ​​class. I saw this somewhere and liked it. But now, creating a listener in Activity0 to assign it to a button in another class, I have a situation that has confused me. The listener must be static, and I cannot use the data in Activity0.
I'm not sure that I explained clearly, if I add something with the code.
I feel like I did something stupid. Tell me how to do it right?
I'll add... Having made several variables in Activity0 static, I managed to work with the received data. I just cannot close Activity0 from a static listener in Activity0. But you must.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmtm, 2019-09-25
@Dmtm

1. forget about static variables in android forever
2. when turning / recreating the activity, unsubscribe the listener from the popup and destroy the popup itself, then re-create the popup and re-transmit the listener
ZYZH also make the listener non-static

A
Andrey, 2019-09-25
@Jinn_000

What conclusion can I draw on this topic? Is it possible to take out the generation of pop-up windows in a separate class out of sight? In case you need to react to events in them. It turns out so?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question