Pregunta

I have a big problem. Firstly, I have a list of items.When user clicks on each item, my app start download file from internet. I have implemented this with AsyncTask serial excutor. After download file completed, my app starts to run Android Installer immediately and when application installed successfully. I want to send device's info to server

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),"application/vnd.android.package-archive");
activity.startActivityForResult(intent, 1);

MainActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 1) {
        List<PackageInfo> packs = this.getPackageManager()
                .getInstalledPackages(0);
        for (int i = 0; i < packs.size(); i++) {
            PackageInfo p = packs.get(i);
            if (InstalledPackageName != null
                    && InstalledPackageName.equals(p.packageName)) {
           //file install success 
                QstoreRestClient rest = new QstoreRestClient(this,
                        "Please wait...");
                SecurityInstallManager secure = new SecurityInstallManager();
                String strDeviceID = getUniqueDeviceId();
                String strProductID = InstalledPackageID;
                String strToken = mToken;
                String strModel = getModelDevice();
                Log.d("QSTORE mUserName", mUserName);
                Log.d("QSTORE strProductID", strProductID);
                Log.d("QSTORE strDeviceID", strDeviceID);
                Log.d("QSTORE strToken", strToken);
                Log.d("QSTORE strModel", strModel);
                String strSHA = secure.getSHAHighscore(mUserName,
                        strDeviceID, strProductID, strToken);
                rest.installShowLoading(mUserName, strProductID,
                        strDeviceID, strSHA, strModel, this);
                Log.d("QSTORE", "Already Installed");
                // return;
            }
        }
        // }

        InstalledPackageName = null;
        InstalledPackageID = null;
    }
    super.onActivityResult(requestCode, resultCode, data);
}

My question: You can see when a file download completed, my app run Android Installer in a new Activity and send the result back to main activity(call OnActivityResult()) The problem here, if user download 5 files,my app run 5 new Activity for install new application so the result of each child activity can't send back to main activity. I'm wondering is there any way to resolve this problem?

¿Fue útil?

Solución

As soon as you finish download of the file, add the file to a Queue. Then you check whether the number of items in the queue is greater than 1 or not. If its greater than 1, do not take any action. If its equal to 1, start the installation. Now, after installation is successful, you remove the entry from the queue. And then do the check again and see if there are any more items in the queue. And then follow the same logic.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top