-1

Here is the code for the main activity which is to be loaded after onCreate method is fully executed.
Refered This for closing one activity from another

public class DictionarySscWords extends AppCompatActivity implements View.OnClickListener, TextToSpeech.OnInitListener 
{
protected void onCreate(Bundle savedInstanceState) 
 {
  super.onCreate(savedInstanceState);
  context = this;
  Intent myIntent = new Intent(DictionarySscWords.this,LoadingIt.class);
  startActivity(myIntent);
  setContentView(R.layout.activity_main);
  //all this activity work
  LoadingIt.fa.finish(); //close Loading activity
 }
}

Now here is the code of my loadingIt activity

public class LoadingIt extends AppCompatActivity {
Context context;
public static LoadingIt fa;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_loading_it);
    context=this;
    fa = this;
    ProgressDialog dialog=new ProgressDialog(context);
    dialog.setMessage("Loading Please wait!!");
    dialog.setCancelable(false);
    dialog.setInverseBackgroundForced(false);
    dialog.show();
}
}

Problem is LoadingIt activity is never finished and app is stuck on Loading screen i want to finish thisactivity as the previous acivity onCreate method is fully executed
thanks

phpdroid
  • 1,642
  • 1
  • 18
  • 36

2 Answers2

0

I feel like your solution is not really best practice. Here is what I would do:

  1. Declare the LoadingIt activity as the startup activity

  2. In the onCreate method, load the resources needed in the background (either with an AsyncTask or a IntentService for example)

  3. Once the loading is finished, finish the LoadingIt activity and display the DictionarySscWords activity

If you post the loading logic, I could provide a sample implementation.

Simon Schiller
  • 644
  • 1
  • 8
  • 23
0

you can use Thread in onCreate() of LoadingIt class

public class LoadingIt extends AppCompatActivity {

   protected void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);
      getSupportActionBar().hide();
      setContentView(R.layout.activity_loading_it);

      Thread loadingThread = new Thread() {

        @Override
        public void run() {
            try {
                super.run();
                sleep(2000);
            } catch (Exception e) {

            } finally {

                Intent main = new Intent(LoadingIt.this,MainActivity.class);
                startActivity(main);
                finish();
            }
        }
    };
    loadingThread.start();
}