Hello.
The essence of the problem is that between SplashScreen , which is shown when you start the program, and the Activity that starts after it, there is a rather large delay.
Those. after the initial screen, the application is minimized, the phone menu is shown, and then after 2-5 seconds the Activity itself opens.
Honestly, at the very beginning everything worked fine, but after changing the code, the behavior changed, and for a couple of days I can not understand what the problem is.
The SplashActivity code SplashActivity (it is not particularly large, so I decided to bring it in full).
public class SplashActivity extends AppCompatActivity { private DatabaseReference databaseReference; private ValueEventListener valueEventListener; private ArrayList<User> userList = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tryToConnect(); finish(); } private void tryToConnect(){ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); if (preferences.getString("Login","").equals("") || preferences.getString("Password","").equals("")){ startActivity(new Intent(this, SignInActivity.class)); finish(); } else { if (hasConnection()) { valueEventListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { userList = Globals.Downloads.getVerifiedUserList(dataSnapshot); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(SplashActivity.this); for (User user : userList) if (user.getLogin().equals(preferences.getString("Login", ""))) signIn(user); } @Override public void onCancelled(DatabaseError databaseError) { Toast.makeText(getApplicationContext(), "Ошибка в работе базы данных. Обратитесь к администратору компании или разработчику", Toast.LENGTH_LONG).show(); } }; databaseReference = FirebaseDatabase.getInstance().getReference(); databaseReference.addValueEventListener(valueEventListener); } else Toast.makeText(getApplicationContext(), "Нет подключения к интернету", Toast.LENGTH_LONG).show(); } } private void signIn(User user){ Toast.makeText(getApplicationContext(), "Вход выполнен", Toast.LENGTH_LONG).show(); if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("allowNotifications", false)) startService(new Intent(this, MessagingService.class)); Globals.currentUser = user; databaseReference.removeEventListener(valueEventListener); startActivity(new Intent(SplashActivity.this, AcceptedTicketsActivity.class)); } private boolean hasConnection() { Runtime runtime = Runtime.getRuntime(); try { Process ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8"); int exitValue = ipProcess.waitFor(); return (exitValue == 0); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return false; } } In the manifest, it is declared as:
<activity android:name=".SplashActivity" android:theme="@style/AppTheme.Launcher"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> Style:
<style name="AppTheme.Launcher"> <item name="android:windowBackground">@drawable/background_splash</item> </style> I tried to chemize with the finish() method, but it did not give any results.
Thank you in advance for your response.