小编omi*_*301的帖子

活动仍然在finish()之后继续;

我有一个测验应用程序,它有一个计时器用于整个游戏活动,你应该在指定的分钟内回答尽可能多的问题.

在指定的分钟结束后,它将带您进入显示您的分数的结果活动.在背面按下时,我创建了一个警告对话框,询问您是否要返回主菜单.如果单击是,则页面应返回主菜单并停止/终止游戏活动.

但是,当我单击"是"时,它将返回主菜单,但当您仍然在应用程序的任何位置时,结果仍将显示我之前的游戏活动.也许我还没有真正完成游戏活动,..这是我的活动中的计时器和背压片段:

new CountDownTimer(seconds, 1000) {
    public void onTick(long millisUntilFinished) {
             timer.setText("Seconds left: " + millisUntilFinished / 1000);
    }   
    public void onFinish() {
             Intent intent = new Intent(GameActivityAddition.this, Score.class);
             intent.putExtra("totalscore", score);
             intent.putExtra("numberquestions", rowId);
             intent.putExtra("d", difficulty);
             db.close();
             startActivity(intent);
    }
}.start();

@Override
public void onBackPressed() {
    AlertDialog.Builder abuilder = new Builder(GameActivityAddition.this);
    abuilder.setMessage("Return to Main Menu?");
    abuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            Intent main = new Intent(GameActivityAddition.this, Main.class);
            startActivity(main);
            finish();           
        }
    });
    abuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {

        public …
Run Code Online (Sandbox Code Playgroud)

android kill-process android-activity

5
推荐指数
1
解决办法
4999
查看次数

我怎样才能得到我的外部/ IP?

可能重复:
如何获取设备的IP地址?

下面是我如何尝试获取外部IP的片段.但是,它没有返回任何东西......

public String getIpAddress() {

    try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet("http://www.whatismyip.com/?404");
            // HttpGet httpget = new HttpGet("http://whatismyip.com.au/");
            // HttpGet httpget = new HttpGet("http://www.whatismyip.org/");
            HttpResponse response;

            response = httpclient.execute(httpget);

            //Log.i("externalip",response.getStatusLine().toString());

            HttpEntity entity = response.getEntity();
            entity.getContentLength();
            str = EntityUtils.toString(entity);
    }
    catch (Exception e)
    {
    }
    return str;

}
Run Code Online (Sandbox Code Playgroud)

ip android http

2
推荐指数
1
解决办法
9846
查看次数

标签 统计

android ×2

android-activity ×1

http ×1

ip ×1

kill-process ×1