English 中文(简体)
Ice Cream桑奇
原标题:Thread on Ice Cream Sandwich

我在ICS 4.0.3上有一个read子。

我用2.33台SE电话和谷歌Nexus S 4.0.3安装了该机。

On SE the apk is running and loading as it s supposed to. However, on Nexus I am getting an error and I have for close it. But i see the program running behind. i have tried to remove the thread(loading screen, splash picture) from the code and run it again on Nexus, and it could run. So i discover my problem is on thread, onCreate thread starting. its any kind of difference from 2.33 to 4.0.3 ?

package my.LigTv.Browser;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.webkit.WebView;
import android.app.AlertDialog;
public class LigTVBrowserActivity extends Activity {
/** Called when the activity is first created. */


WebView mWebView;
AlertDialog alertDialog;
protected boolean _active = true;
protected int _splashTime = 3000; // time to display the splash screen in ms
int progress = 0;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);



    final Activity activity = this;

    final ProgressDialog progressDialog = new ProgressDialog(activity);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage("Please wait for the applet to load");

    progressDialog.show();
    progressDialog.setProgress(0);
    activity.setProgress(progress * 1000);

    progressDialog.incrementProgressBy(progress);

    if(progress == 100 && progressDialog.isShowing())
        progressDialog.dismiss(); 



    Thread splashTread = new Thread() {
        @Override
        public void run() {                 
            try {
                int waited = 0;
                while(_active && (waited < _splashTime)) {
                    sleep(100);

                    if(_active) {
                        waited += 100;                                                    
                        }
                }
            } catch(InterruptedException e) {
                // do nothing
            } finally {
                finish();
                startActivity(new Intent("my.LigTv.Browser.Starter"));
                stop();
            }
        }
    };
    splashTread.start();
}    

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        _active = false;
    }
    return true;
}

 }
最佳回答

在新活动开始后请打<代码>finish()。 另外,你为什么在读物上打上<条码>。 一旦新活动开始,它将停止。 这是我已经写成的一个例子,正如你所希望的那样,我们做了改动:

            Runnable r1 = new Runnable(){
                public void run(){
                    new Handler().postDelayed(new Runnable(){
                        @Override
                        public void run(){
                            startActivity(new Intent(Splash.this,Main.class));
                            overridePendingTransition(R.anim.fade_out, R.anim.fade_in);
                            finish();

                        }
                    }, waitTime);
                }
            };
            runOnUiThread(r1);
问题回答

我陷入了同样的问题,我把它定下来了一条像快速确定的那样的法典:

private Timer myTimer;
private int x=0;
private int interval=2500;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);

    myTimer = new Timer();
    myTimer.schedule(new TimerTask() {
        @Override
        public void run() {
            TimerMethod();
        }

    }, 0, interval);

}

private void TimerMethod()
{
    this.runOnUiThread(Timer_Tick);
}

private Runnable Timer_Tick = new Runnable() {
public void run() {
    if(x==1)
    {
        SplashActivity.this.finish();
        startActivity(new Intent(SplashActivity.this,LoginActivity.class));
    }
    x++;
}
};

但没有进展,

如果你想要这样做,当用户点击闪电屏幕时,他就会去做下一个活动,取消时间,完成大火活动,然后去做。

这一点应该read。

     runOnUiThread(new Runnable(){
                finish();
                startActivity(new Intent("my.LigTv.Browser.Starter"));
                stop();
});




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签