0

I need to that when i open the application, the screen saver works and the main activity opens. But so that during the splashscreen, the main activity is already loaded. In articles and videos, they do it via postdelayed, which does not suit me(that is, the user first waits for the splashscr, and then still waits for the main activity to load). I might as well use thrsleep. I was thinking of doing it through Asynctask and putting the opening in the background or onpreExecute, but then the activity will probably open immediately without a splashscr. Please help, or suggest an idea. I also came across this article and this, but the app also continues to load after the splash screen. The launcher activity in the manifest I have a login window. From it, it goes to the splashscr, and from there to the main activity.

Domex
  • 27
  • 5
  • 1
    Please add more details, first your objective, then your progress and then issue that you are facing... – Hafiza Feb 25 '21 at 11:41
  • Ok, in the main activity I have a subload of information about the user(that is, all his data), pageradapter with 6 fragments. The first one loads the chat with users and their latest messages. In the second fragment, schedule for this user(application for students). In the third, the news. Etc. The schedule contains the logic for highlighting the current lesson(If the lesson is over, it displays the next lesson.) And to download all this, it takes some time. I hope I described it in enough detail. – Domex Feb 25 '21 at 13:44

1 Answers1

1

You Can use full screen Dialog

Use Full Screen Dialog With Runnable on Main Activity

public void showsplash() {

final Dialog dialog = new Dialog(MainActivity.this,
android.R.style.Theme_Black_NoTitleBar_Fullscreen);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.activity_splash_screen);
dialog.setCancelable(true);
dialog.show();

final Handler handler  = new Handler();
final Runnable runnable = new Runnable() {
    @Override
    public void run() {
        {
           dialog.dismiss();
        }
    }
};
handler.postDelayed(runnable, 30000);
}
Usama Altaf
  • 1,036
  • 1
  • 4
  • 23
  • quite hard to understand what OP wants specifically, they say that `they do it via postdelayed, which does not suit me(that is, the user first waits for the splashscr, and then still waits for the main activity to load)` so i'm not sure if this will actually answer their question – a_local_nobody Feb 25 '21 at 11:48
  • Yes in this answer dialog will show in the main activity for the specific time while the main activity will load – Usama Altaf Feb 25 '21 at 11:50
  • Op wants to show something while MainActivity is loading – Usama Altaf Feb 25 '21 at 11:52
  • but by using `handler.postDelayed(runnable, 30000);` there's no guarentee that their mainActivity will have loaded already, right ? 30000 is just a random amount of time which _could_ work,but it _could_ also be too long/short. if they're doing service calls, it would be better for them to complete/fail before showing another activity – a_local_nobody Feb 25 '21 at 11:54
  • @yeah you are right this is not a perfect solution – Usama Altaf Feb 25 '21 at 11:55
  • questions like these are too hard to answer without OP giving more/enough detail, they just lead to answers which don't really work, that's the point i've been trying to get to you in the past – a_local_nobody Feb 25 '21 at 11:56
  • 1
    Okay! And by the way sorry for the past. – Usama Altaf Feb 25 '21 at 11:58
  • I'm sorry, in the comment above I described my problem in more detail. – Domex Feb 25 '21 at 13:46