开发者

Application crashes on second run using splash screen

开发者 https://www.devze.com 2023-04-08 21:18 出处:网络
In My application, I am using thread to show the splash screen. . . But i have also given the Android Licensing to My Application. Which also uses the thread. . .

In My application, I am using thread to show the splash screen. . . But i have also given the Android Licensing to My Application. Which also uses the thread. . . But While i am installing the Application it runs once.. if i again open it then it got crash. where is the problem ??? the code is as below :

   package com.EMTPrep.Paramedic.app;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings.Secure;
import android.view.Window;
import com.android.vending.licensing.AESObfuscator;
import com.android.vending.licensing.LicenseChecker;
import com.android.vending.licensing.LicenseCheckerCallback;
import com.android.vending.licensing.ServerManagedPolicy;
import com.EMTPrep.Paramedic.app.R;

public class SplashActivity extends Activity 
{

    private static boolean DEBUG = false;
    private static int DURATION;
    private Handler splashHandler;
    private Runnable launcherRunnable;

     private LicenseCheckerCallback mLicenseCheckerCallback;// for the License
     private LicenseChecker mChecker;// for the License
     // === A handler on the UI thread.
     private Handler mHandler;

     private static final String BASE64_PUBLIC_KEY = "I have puted the Licensing code here";//// for the License
     // === Generate your own 20 random bytes, and put them here.
     private static final byte[] SALT = new byte[] 
                {
            -46, 65, 90, -128, -13, -57, 74, -64, 51, 66, -85, -67, 89, -114, -36, 113, 77, 32, -64,
            89
        }; // for the License

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.splash);

         mHandler = new Handler();

        // Try to use more data here. ANDROID_ID is a single point of attack.
        String deviceId = Secure.getString(getContentResolver(), Secure.ANDROID_ID);// for the License
        // === Library calls this when it's done.
        mLicenseCheckerCallback = new MyLicenseCheckerCallback();// for the License
        // === Construct the LicenseChecker with a policy.
        mChecker = new LicenseChecker(this, new ServerManagedPolicy(this,new AESObfuscator(SALT, getPackageName(), deviceId)),// for the License
                BASE64_PUBLIC_KEY);// for the License
        doCheck();// for the License


        DURATION = Integer.valueOf(getString(R.string.splash_duration));

        splashHandler = new Handler();

//  ================ Main Code of the Application

//      launcherRunnable = new Runnable() {
//          @Override
//          public void run() {
//              Intent i = new Intent(SplashActivity.this, MainMenuActivity.class);
//              i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//              startActivity(i);
//              SplashActivity.this.finish();
//          }
//      };
//      if (DEBUG)
//      {
//          splashHandler.post(launcherRunnable);
//      }
//      else
//          splashHandler.postDelayed(launcherRunnable, DURATION);
//

    }
    protected Dialog onCreateDialog(int id) //// for the License 
    {
        // We have only one dialog.
        return new AlertDialog.Builder(this)
            .setTitle(R.string.unlicensed_dialog_title)
            .setMessage(R.string.unlicensed_dialog_body)
            .setPositiveButton(R.string.buy_button, new DialogInterface.OnClickListener() 
            {
                public void onClick(DialogInterface dialog, int which) 
                {
                    Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(
                        "http://market.android.com/details?id=" + getPackageName()));
                    startActivity(marketIntent);
                }
            })
            .setNegativeButton(R.string.quit_button, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            })
            .create();
    }

    private void displayResult(final String result) { // for the License
        mHandler.post(new Runnable() {
            public void run() {
               // mStatusText.setText(result);
                setProgressBarIndeterminateVisibility(false);
                //mCheckLicenseButton.setEnabled(true);
            }
        });
    }

    private class MyLicenseCheckerCallback implements LicenseCheckerCallback // for the License 
    {        
        public void allow() 
        {            
            if (isFinishing()) 
            {                
                // Don't update UI if Activity is finishing.                
                return;            
            }            
            // Should allow user access.  

            launcherRunnable = new Runnable() 
            {
                @Override
                public void run() 
                {
                    Intent i = new Intent(SplashActivity.this, MainMenuActivity.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                    SplashActivity.this.finish();
                }
            };

            if (DEBUG)
            {
                splashHandler.post(launcherRunnable);
            }
            else
                splashHandler.postDelayed(launcherRunnable, DURATION);

            displayResult(getString(R.string.allow));        
        }        
        public void dontAllow() 
        {            
            if (isFinishing()) 
            {                
                // Don't update UI if Activity is finishing.                
                return;            
            }            

            displayResult(getString(R.string.dont_allow));            

            // Should not allow access. An app can handle as needed,            
            // typically by informing the user that the app is not licensed            
            // and then shutting down the app or limiting the user to a            
            // restricted set of features.            
            // In this example, we show a dialog that takes the user to Market.            
            showDialog(0);        
        }

         public void applicationError(ApplicationErrorCode errorCode) 
            {
                if (isFinishing()) 
                {
                    // Don't update UI if Activity is finishing.
                    return;
                }
                // This i开发者_开发百科s a polite way of saying the developer made a mistake
                // while setting up or calling the license checker library.
                // Please examine the error code and fix the error.
                String result = String.format(getString(R.string.application_error), errorCode);
                displayResult(result);
            }

    }
     private void doCheck()// for the License 
        {
            //mCheckLicenseButton.setEnabled(false);
            setProgressBarIndeterminateVisibility(true);
            //mStatusText.setText(R.string.checking_license);
            mChecker.checkAccess(mLicenseCheckerCallback);
        }
     @Override // for the License
        protected void onDestroy() {
            super.onDestroy();
            mChecker.onDestroy();
        }
}

I think there might be the problem in thread. . . Please help me to solve it. . Thanks Please help me in this. . . And let me tell while i am able to run the application only at once. . . Thanks in advance.


Can you try splashHandler.postDelayed(new Runnable(), DURATION); ?

and put it up to fields private Handler splashHandler = new Handler();

0

精彩评论

暂无评论...
验证码 换一张
取 消