public class LoaderThread extends Thread{
 public void run() {
        android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

红色部分帮错~~~该怎么办?

解决方案 »

  1.   

    这是提升线程优先级吧;用了这个没:<uses-permission id="android.permission.RAISED_THREAD_PRIORITY"/>
      

  2.   

    使用HandlerThread,既不用考虑looper的问题,也能设置优先级,是handler和thread的合体!
      

  3.   

    为了防止ANR,我把一个耗时的操作放到线程里面做了,可是好象没有起任何作用,不知道怎么回事?
      

  4.   

    1. 线程同步问题要处理好,不能调用阻塞函数,或在主线程的一个message loop周期中处理这个同步操作
    (发消息->等回应)
    2. 后台线程优先级要稍微低一点。 
      

  5.   

    比如说:updatetable(){
    //这里面都是些耗时的操作,我把它放在线程里面做了~~~

    public class LoaderThread extends Thread{
    public void run() {
      android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
      updatetable();

    可是这个动作丝毫不能起任何作用?
    该怎么办?
      

  6.   

    Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);    /**
         * Set the priority of a thread, based on Linux priorities.
         * 
         * @param tid The identifier of the thread/process to change.
         * @param priority A Linux priority level, from -20 for highest scheduling
         * priority to 19 for lowest scheduling priority.
         * 
         * @throws IllegalArgumentException Throws IllegalArgumentException if
         * <var>tid</var> does not exist.
         * @throws SecurityException Throws SecurityException if your process does
         * not have permission to modify the given thread, or to use the given
         * priority.
         */看样子是调整process的nice值的,这个估计你apk是没有权限做的。
      

  7.   

    而且你设置进程的priority有啥用呢要设置线程的proritymyThread =new MyThread
    myThread.setPriority(xxxx)
    start完了在设置它具体接口查下sdk吧,忘了
      

  8.   

    android.os.Process.setThreadPriority是设置进程的,一般没有权限这么做的,只有root或超级用户才行。 而且进程的权限只是在linux做对进程的schedule时才有用,而线程只是属于进程的。Thread.setPriority是设置线程的优先级,对你这里比较合适。另外注意updatetable();
    函数,最好不要和主线程有同步的东西,以免因为同步阻塞了主线程,造成ANR
      

  9.   

    好久的问题了 我忍不住要来说说。 
    android中有两个  Process 类  
    一个是 android.os.Process  一个是  java.lang.Process. 
    而java.lang包是默认导入的 所以楼主遇到的问题应该是  没有导入android.os.Process 类。 
    import一下 就ok了。 楼上都是大牛。
    另外废话一句 
    没有加权限 是运行时异常  Runtime Exception
    楼主这里遇到的是编译错误。