The following things you can do to avoid the situation:
A developer can perform lengthy database and networking operating in individual threads.
Create a child thread and put a part of the code that is non-responsive for a long time. Keep that part away from the main thread so that it can respond in a minimum required time.
Release the pressure on UI by using the IntentService method.