在我的应用程序中,我使用线程来显示启动画面。 。 。 但我也已将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 :(得分:1)
你能试试splashHandler.postDelayed(new Runnable(), DURATION); ?
并将其添加到字段private Handler splashHandler = new Handler();