Just construct the Dialog and directly pass the Activity context to it. You don’t need to bother with callbacks or anything like that. You can refer to other people's packaged tool libraries to see other people's ideas.
Originally, the system-level dialog is very convenient. You only need to pass in the applicationContext to implement a pop-up box. However, due to excessive customization by various manufacturers (I encountered Xiaomi’s system-level pop-up box customization is disgusting, the same version, update Modify once after implementation), so it is best to use an activity in a customized dialog format as a pop-up box to implement all the above. Many companies currently do this, such as tencent’s carrier pigeon push, which can ensure Launch successfully without the hassle of customization.
Android Dialog, you have to pass the Context no matter what. Passing Activity is actually equivalent to passing Context. It is not possible to use Application's Context; furthermore, static Context is not recommended and may cause memory leaks.
However, you can hide or simplify this process through methods such as dependency injection.
You can’t (although I want to say I don’t recommend it) Building you have already implemented it, let’s guess what will happen.
The network request was sent, and then the page was ended, but the request was not canceled. When the request returned, a dialog box popped up. How to explain this Dialog? If this Dialog has subsequent operations and the operations have data, where should these processing codes be placed? ?Alright, you successfully put these data in the Dialog instance and created a new internal class. Congratulations, the memory of the Activity that was just ended is leaked
How to restrict people from using a universal Dialog? It can be played anywhere and the code structure can be maintained?
For a small project, you can directly create a BaseActivity according to your needs, handle the code structure and pop up a dialog box without much trouble. The reason is not sufficient.
Yes, you can, but why? Just encapsulate a dialog tool class and pass the activity. As for toast, using applicationContext is a good idea.
Just construct the Dialog and directly pass the Activity context to it. You don’t need to bother with callbacks or anything like that. You can refer to other people's packaged tool libraries to see other people's ideas.
Just be smart, you can use an activity as a dialog, just set its theme to dialog, as the official website says
Originally, the system-level dialog is very convenient. You only need to pass in the applicationContext to implement a pop-up box. However, due to excessive customization by various manufacturers (I encountered Xiaomi’s system-level pop-up box customization is disgusting, the same version, update Modify once after implementation), so it is best to use an activity in a customized dialog format as a pop-up box to implement all the above. Many companies currently do this, such as tencent’s carrier pigeon push, which can ensure Launch successfully without the hassle of customization.
Android Dialog, you have to pass the Context no matter what. Passing Activity is actually equivalent to passing Context. It is not possible to use Application's Context; furthermore, static Context is not recommended and may cause memory leaks.
However, you can hide or simplify this process through methods such as dependency injection.
You can’t (although I want to say I don’t recommend it)
Building you have already implemented it, let’s guess what will happen.
The network request was sent, and then the page was ended, but the request was not canceled. When the request returned, a dialog box popped up. How to explain this Dialog? If this Dialog has subsequent operations and the operations have data, where should these processing codes be placed? ?Alright, you successfully put these data in the Dialog instance and created a new internal class. Congratulations, the memory of the Activity that was just ended is leaked
How to restrict people from using a universal Dialog? It can be played anywhere and the code structure can be maintained?
For a small project, you can directly create a BaseActivity according to your needs, handle the code structure and pop up a dialog box without much trouble. The reason is not sufficient.