1

I am loading some data in MainActivity and trying to show a splash screen while loading. I can't use another activity as I am loading data in main activity only, so I am using dialogs to display a picture.

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        loading_dialog = new Dialog(MainActivity.this);
        loading_dialog.setContentView(R.layout.loading);
        loading_dialog.show();
        Log.d(TAG,"show");
        verifyPermissions(this);
        res=new Resourses(this);
        manager = new Manager(this, res);
        loading_dialog.dismiss();
        setContentView(R.layout.activity_main);
        Log.d(TAG,"End");

        view = (GLSurfaceView) findViewById(R.id.view);

        view.setEGLConfigChooser(8, 8, 8, 8, 16, 0);

        view.setRenderer(manager);



        additionalSkuList = new ArrayList<String>();
        for(int i=0;i<10;i++)
        {
            additionalSkuList.add(res.id[i]);
        }
        String base64EncodedPublicKey;
        base64EncodedPublicKey= getResources().getString(R.string.inappkey);
        mHelper = new IabHelper(this, base64EncodedPublicKey);
        mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            public void onIabSetupFinished(IabResult result) {
                //     Log.d("main", "m here");
                if (!result.isSuccess()) {
                    // Oh noes, there was a problem.
                    Log.d(TAG, "Problem setting up In-app Billing: " + result);
                }
                // Hooray, IAB is fully set up!
                isIAB = true;
                  Log.d(TAG,""+isIAB);
                mHelper.queryInventoryAsync(true, additionalSkuList, mQueryFinishedListener);
                //  Log.d("main", "" + isIAB + " " + isLoad);
            }
        });
        // ATTENTION: This was auto-generated to implement the App Indexing API.
        // See https://g.co/AppIndexing/AndroidStudio for more information.

    }

But the dialog is not displaying untill the oncreate method is done. If I run this I can't see the dialog screen. If I switch off the loading_dialog.dismiss() then its loading after all data is loaded.

Can anyone identify the problem?

SOLVED:

The problem was, setContentView doesn't initiate unless you initialize renderer's construction.

So I had to shift the data load in the GLSurfaceView's onSurfaceCreated function. Thus data got loaded after the Content view was initialized.

sabby
  • 99
  • 7
  • 1
    if comment `loading_dialog.dismiss();` line then it is showing or not? – ρяσѕρєя K May 12 '16 at 08:11
  • yes if I comment the dismiss its showing after all files are loaded. After the END tag its showing – sabby May 12 '16 at 08:14
  • what are you doing it these liens.. `verifyPermissions(this); manager = new Manager(this, res);` is there an AsyncTask?? – SRB Bans May 12 '16 at 08:15
  • verifyPermissions is just checking android manifest permissions and in res & manager I am loading data. I want to show the dialog screen while these classes gets initialized. – sabby May 12 '16 at 08:16
  • are you loading data in AsyncTask or Thread??? – SRB Bans May 12 '16 at 08:19
  • You should consider using ProgressDialog, or alternatively can you the recommended ["progress or activity indicators"](https://www.google.com/design/spec/components/progress-activity.html#activity) - see an example [here](http://stackoverflow.com/questions/12316365/how-can-i-display-a-holo-themed-activity-circle). – ishmaelMakitla May 12 '16 at 08:26

3 Answers3

1

Try using an AsyncTask and load the data on the doInBackground() method.

Refer to this on using an AsyncTask.

Community
  • 1
  • 1
esfox
  • 175
  • 3
  • 11
  • I am loading data from Raw folder into the GLSurfaceView class. How can I run it in Async class? Its giving error saying performing on null object – sabby May 12 '16 at 09:10
1

If you are making network call, use Volley or RetroFit libraries. Else use Async task onPreExecute() method to show dialog, doInBackground() to do whatever you want and onPostExecute() to dismiss the dialog.

am110787
  • 316
  • 1
  • 2
  • 9
  • How can I initialize a class in Async task? its giving error. I tried this: class ... in main activity MyAsyncTask mt = new MyAsyncTask(); mt.execute(); – sabby May 12 '16 at 09:07
0

Use Frame Layout. Add picture to a frame and hide the activity frame in xml file. Once the data is loaded make the activity frame visible and picture frame visibility gone.