2011-09-26 132 views
0

在我的应用程序中,我使用线程来显示启动画面。 。 。 但我也给了我的应用程序Android授权。其中也使用该线程。 。 。 但是,当我安装应用程序它运行一次.. 如果我再次打开它然后它崩溃。哪里有问题 ??? 代码如下:使用启动画面在第二次运行时应用程序崩溃

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 is 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(); 
     } 
} 

我觉得可能是这个问题的线索。 。 。请帮我解决它。 。谢谢 请在这帮我。 。 。 让我告诉,而我能够只运行一次应用程序。 。 。 在此先感谢。

+0

什么logcat的表演,当你的应用程序崩溃...? –

+0

好的。一段时间后我会放logcat。直到那你会检查它的线程?因为我得到了类似于144的错误,并且它说NullPointerException。在这个活动中。 –

+0

你能告诉144行有什么吗? –

回答

1

你可以尝试splashHandler.postDelayed(new Runnable(), DURATION); ?

,并把它高达领域private Handler splashHandler = new Handler();

相关问题