在micromax A47上我的应用程序后退没有响应,并返回一个带有等待和取消按钮的对话框。而在其他设置上它的工作完全正确。你可以帮助我使用我的代码或链接指南如何正确实现这一点? 这是我的代码:
public class MainActivity extends Activity implements AnimationListener{
boolean running = true;
boolean isSIM1Ready;
boolean isSIM2Ready;
ProgressWheel pw_two;
TelephonyInfo telephonyInfo;
Handler updateBarHandler;
Context context;
Animation animBlink;
int progress = 0;
private WebView wvPlay;
private WebView wvPlay1;
private TextView tvWait;
private AlertDialog alert;
private DataBaseHandler bdb;
private Runnable r ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
pw_two = (ProgressWheel) findViewById(R.id.progressBarTwo);
pw_two.bringToFront();
tvWait = (TextView) findViewById(R.id.tvWait);
tvWait.setVisibility(View.GONE);
wvPlay = (WebView) findViewById(R.id.wvPlay);
wvPlay.setBackgroundColor(0xffdcffff);
wvPlay.loadUrl("file:///android_asset/progress.gif");
wvPlay.setVisibility(View.GONE);
wvPlay1 = (WebView) findViewById(R.id.wv);
wvPlay1.setBackgroundColor(0xffdcffff);
wvPlay1.loadUrl("file:///android_asset/logo.gif");
animBlink = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.blink);
animBlink.setAnimationListener(this);
telephonyInfo = TelephonyInfo.getInstance(this);
isSIM1Ready = telephonyInfo.isSIM1Ready();
isSIM2Ready = telephonyInfo.isSIM2Ready();
progress = 361;
pw_two.stopSpinning();
pw_two.resetCount();
bdb = new DataBaseHandler(MainActivity.this);
Handler mainHandler = new Handler(Looper.getMainLooper());
r = new Runnable(){
public void run(){
try{
running = true;
while(progress<361) {
pw_two.incrementProgress();
progress++;
try {
Thread.sleep(15);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
running = false;
if(running == false){
pw_two.startAnimation(animBlink);
}
}
catch(Exception e){
Log.e("Exception", "******Exception*****" +e);
}
}
};
mainHandler.post(r);
pw_two.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try{
Log.e("TAG", "***********");
if(!running) {
WindowManager manager = (WindowManager)getApplicationContext() .getSystemService(Context.WINDOW_SERVICE);
Display mDisplay = manager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(displayMetrics);
switch(displayMetrics.densityDpi)
{
case DisplayMetrics.DENSITY_MEDIUM:
tvWait.setVisibility(View.GONE);
break;
case DisplayMetrics.DENSITY_LOW:
tvWait.setVisibility(View.GONE);
break;
case DisplayMetrics.DENSITY_HIGH:
tvWait.setVisibility(View.VISIBLE);
break;
case DisplayMetrics.DENSITY_XHIGH:
tvWait.setVisibility(View.VISIBLE);
break;
case DisplayMetrics.DENSITY_XXHIGH:
tvWait.setVisibility(View.VISIBLE);
break;
}
wvPlay.setVisibility(View.VISIBLE);
progress = 0;
pw_two.resetCount();
Thread s = new Thread(r);
s.start();
try {
Thread.sleep(300);
sendMessage();
SimpleDateFormat dfDate_day1 = new SimpleDateFormat("dd/MM/yyyy HH:mm");
Calendar cal1 = Calendar.getInstance();
String dt1 = dfDate_day1.format(cal1.getTime());
bdb.insertButtonPresses(1, dt1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Thread timer=new Thread(){
public void run(){
try
{
sleep(30000);
showAlert("Its taking time to get the activated VAS Services, please wait for few seconds ...");
}
catch(Exception e){
Log.e("Show Alert Message", "********"+e);
}
}
};
timer.start();
Thread timer1=new Thread(){
public void run(){
try
{
sleep(45000);
showAlert2();
}
catch(Exception e){
Log.e("Show Alert Message", "********"+e);
}
}
};
timer1.start();
}
catch(Exception e){
Log.e("Exception", "******Exception*****" +e);
}
}
});
}
@SuppressLint("ShowToast")
public void sendMessage()
{
SmsManager.getDefault().sendTextMessage("155223", null, "STOP", null, null);
SimpleDateFormat dfDate_day = new SimpleDateFormat("dd/MM/yyyy HH:mm");
Calendar cal = Calendar.getInstance();
String dt = dfDate_day.format(cal.getTime());
bdb.insertSMS("Me","Your request to check activated services has been initiated ",dt,0);
TelephonyManager telephonyManager =((TelephonyManager)MainActivity.this.getSystemService(Context.TELEPHONY_SERVICE));
String operatorName = telephonyManager.getSimOperatorName();
Vector<User> vctNumber = bdb.getPhoneNumber();
String mobile = "";
for(int i = 0; i< vctNumber.size(); i++){
User usr = (User)vctNumber.elementAt(i);
mobile = usr.getNumber();
Log.v("mobile", "**********"+mobile);
}
bdb.insertMsg(mobile, "", "STOP", "", dt, operatorName, "155223", "", "", "", "");
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onAnimationEnd(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
private void showAlert(final String error){
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
View al = inflater.inflate(R.layout.title_timeout, null);
builder.setView(al);
alert = builder.create();
alert.setCanceledOnTouchOutside(true);
if(MainActivity.this.isFinishing()){
alert.dismiss();
}else{
alert.show();
}
}
});
}
private void showAlert2(){
MainActivity.this.runOnUiThread(new Runnable() {
public void run() {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = LayoutInflater.from(getApplicationContext());
View al = inflater.inflate(R.layout.title_timeout_second, null);
builder.setView(al);
alert = builder.create();
alert.setCanceledOnTouchOutside(true);
Button btnOk = (Button)al.findViewById(R.id.btnOk);
btnOk.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
tvWait.setVisibility(View.GONE);
wvPlay.setVisibility(View.GONE);
progress = 361;
pw_two.stopSpinning();
pw_two.resetCount();
alert.dismiss();
}
catch(Exception e){
Log.e("MainActivity", "45000 Exception**********"+e);
}
}
});
if(MainActivity.this.isFinishing()){
alert.dismiss();
}else{
alert.show();
}
}
});
}
}