2012-04-06 12 views
0

アンドロイドを作る方法2.2アプリはアンドロイド4で動作しますか? 偉大なリファクタリングの仕事ですか?またはプロジェクトで変更するのはちょうどいくつかのSDK設定ですか?アンドロイド4でアンドロイド2.2アプリを作る方法は?

BTW:より良い場合: - アンドロイド4で動作するアンドロイド2.2アプリに適合していますか? - Googleからの互換性パッケージのAndroidアプリ4?

ありがとうございます。

EDIT: 私のアプリは、Android 2.2と2.3で正常に動作しますが、アンドロイド4.

のStackTraceでクラッシュしたので、私はこれを頼む:

E/AndroidRuntime( 660): FATAL EXCEPTION: main 
E/AndroidRuntime( 660): java.lang.RuntimeException: Unable to start activity ComponentInfo{vex.android/vex.android.controllers.ControllerLoginView}: java.lang.NullPointerException 
E/AndroidRuntime( 660): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 
E/AndroidRuntime( 660): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
E/AndroidRuntime( 660): at android.app.ActivityThread.access$600(ActivityThread.java:123) 
E/AndroidRuntime( 660): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
E/AndroidRuntime( 660): at android.os.Handler.dispatchMessage(Handler.java:99) 
E/AndroidRuntime( 660): at android.os.Looper.loop(Looper.java:137) 
E/AndroidRuntime( 660): at android.app.ActivityThread.main(ActivityThread.java:4424) 
E/AndroidRuntime( 660): at java.lang.reflect.Method.invokeNative(Native Method) 
E/AndroidRuntime( 660): at java.lang.reflect.Method.invoke(Method.java:511) 
E/AndroidRuntime( 660): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
E/AndroidRuntime( 660): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
E/AndroidRuntime( 660): at dalvik.system.NativeStart.main(Native Method) 
E/AndroidRuntime( 660): Caused by: java.lang.NullPointerException 
E/AndroidRuntime( 660): at vex.android.layout.layout_titleheader.setButtonVisibility(layout_titleheader.java:163) 
E/AndroidRuntime( 660): at vex.android.layout.layout_titleheader.setButtonVisibility(layout_titleheader.java:155) 
E/AndroidRuntime( 660): at vex.android.controllers.ControllerLoginView.Initialize(ControllerLoginView.java:58) 
E/AndroidRuntime( 660): at vex.android.definition.VexActivity.onStart(VexActivity.java:154) 
E/AndroidRuntime( 660): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1133) 
E/AndroidRuntime( 660): at android.app.Activity.performStart(Activity.java:4475) 
E/AndroidRuntime( 660): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1929) 
E/AndroidRuntime( 660): ... 11 more 

がlayout_titleheader.java:

package vex.android.layout; 

    import vex.android.R; 
    import vex.android.controllers.ControllerInfo; 
    import vex.android.definition.VexLayout; 
    import vex.android.definition.iVexParentable; 
    import vex.android.definition.intentCode; 
    import android.app.Activity; 
    import android.app.Instrumentation; 
    import android.content.Context; 
    import android.content.Intent; 
    import android.os.Handler; 
    import android.os.SystemClock; 
    import android.util.AttributeSet; 
    import android.view.KeyEvent; 
    import android.view.MotionEvent; 
    import android.view.View; 
    import android.widget.Button; 
    import android.widget.ImageButton; 
    import android.widget.ImageView; 


    public class layout_titleheader extends VexLayout 
    { 
     /*** CONTROL POINTERS ***/ 
     Button nextButton; 
     Button prevButton; 
     ImageView infoButton; 
     ImageButton upButton; 
     ImageButton downButton; 

     private Handler handler = new Handler(); 
     private Runnable upTask = new Runnable() { 
      public void run() { 
       if(getContext() instanceof iVexParentable) { 
        ((iVexParentable)getContext()).onUpButton(); 
       } 
       handler.postAtTime(this, SystemClock.uptimeMillis() + 100); 
      } 
     }; 
     private Runnable downTask = new Runnable() { 
      public void run() { 
       if(getContext() instanceof iVexParentable) { 
        ((iVexParentable)getContext()).onDownButton(); 
       } 
       handler.postAtTime(this, SystemClock.uptimeMillis() + 100); 
      } 
     }; 

     /**** CONSTRUCTORS ****/ 
     public layout_titleheader(Context context) 
     { 
      super(context); 
      ((Activity)getContext()).getLayoutInflater().inflate(R.layout.layout_titleheader, this); 
     } 
     public layout_titleheader(Context context, AttributeSet attrs) { 
      super(context, attrs); 
      ((Activity)getContext()).getLayoutInflater().inflate(R.layout.layout_titleheader, this); 
     } 

     /**** INITIALIZERS ****/ 
     @Override 
     public void Initialize() 
     { 
      infoButton.setOnTouchListener(new OnTouchListener(){ 
       @Override 
       public boolean onTouch(View v, MotionEvent event) { 
        if(event.getAction() == MotionEvent.ACTION_DOWN) 
        { 
         showInfo(); 
        } 
        return true; 
       } 
      }); 

      prevButton.setOnTouchListener(new OnTouchListener(){ 
       @Override 
       public boolean onTouch(View v, MotionEvent event) { 
        if(event.getAction() == MotionEvent.ACTION_DOWN) 
        { 
         new Thread(new Runnable() { 
          @Override 
          public void run() { 
           Instrumentation i = new Instrumentation(); 
           i.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK); 
          } 
         }).start(); 
        } 
        return true; 
       } 
      }); 

      nextButton.setOnTouchListener(new OnTouchListener(){ 
       @Override 
       public boolean onTouch(View v, MotionEvent event) { 
        if(event.getAction() == MotionEvent.ACTION_DOWN) 
        { 
         if(getContext() instanceof iVexParentable) 
         { 
          ((iVexParentable)getContext()).onEditButton(); 
         } 
        } 
        return true; 
       } 
      }); 
      upButton.setOnTouchListener(new OnTouchListener() { 
       public boolean onTouch(View view, MotionEvent motionevent) { 
        int action = motionevent.getAction(); 
        if (action == MotionEvent.ACTION_DOWN) { 
         handler.removeCallbacks(upTask); 
         handler.postAtTime(upTask, SystemClock.uptimeMillis() + 100); 
        } else if (action == MotionEvent.ACTION_UP) { 
         handler.removeCallbacks(upTask); 
        } 
        return false; 
       } 
      }); 

      downButton.setOnTouchListener(new OnTouchListener(){ 
       @Override 
       public boolean onTouch(View v, MotionEvent motionevent) { 
        int action = motionevent.getAction(); 
        if (action == MotionEvent.ACTION_DOWN) { 
         handler.removeCallbacks(downTask); 
         handler.postAtTime(downTask, SystemClock.uptimeMillis() + 100); 
        } else if (action == MotionEvent.ACTION_UP) { 
         handler.removeCallbacks(downTask); 
        } 
        return false; 
       } 
      }); 
     } 

     @Override 
     public void InitializeControls() 
     { 
      infoButton = (ImageView)findViewById(R.id.infoButton); 
      prevButton = (Button)findViewById(R.id.prevButton); 
      nextButton = (Button)findViewById(R.id.nextButton); 
      upButton = (ImageButton)findViewById(R.id.upButton); 
      downButton = (ImageButton)findViewById(R.id.downButton); 
     } 

     /**** LOCAL METHODS ****/ 
     public void showInfo() 
     { 
      if(getContext() instanceof Activity) 
      { 
       Intent intent = new Intent(getContext(), ControllerInfo.class); 
       ((Activity)getContext()).startActivityForResult(intent, intentCode.INFO_DOSTART); 
      } 
     } 
     public void setButtonVisibility(int previousButton, int editButton, int helpButton) 
     { 
      setButtonVisibility(previousButton, editButton, helpButton, View.INVISIBLE, View.INVISIBLE); 
     } 

     public void setButtonVisibility(int previousButton, int editButton, int helpButton, int upButtonVisibility, int downButtonVisibility) 
     { 
      if (View.VISIBLE == previousButton) {// fixes issue of translation not correctly displayed 
       prevButton.setText(getContext().getString(R.string.Back)); 
      } 
      prevButton.setVisibility(previousButton); 
      nextButton.setVisibility(editButton); 
      infoButton.setVisibility(helpButton); 
      upButton.setVisibility(upButtonVisibility); 
      downButton.setVisibility(downButtonVisibility); 
     } 

     public void setPreviousButtonText(int id) { 
      prevButton.setText(getContext().getString(id)); 
     } 

     public void setEditButtonName(int resId) 
     { 
      nextButton.setText(resId); 
     } 
    } 

いくつかの調査の後、私は、VexLayoutでオーバーライドされているViewクラスのonFinishInflate()がアンドロイドを実行しているときに呼び出されないことを発見しました。

+0

(int型、int型、int型、int型、int)メソッドにnullをgetContextまたはContext.getString(int)戻り、(たとえばprevButtonまたはnextButton用)のいずれかのビューがnullと等しいかどうかを確認する setButtonVisibilityを試してみてくださいあなたはクラッシュのスタックダンプを提供する、誰かがあなたを助けることができる可能性があります。 – mah

+0

あなたの 'layout_titleheader.java'を見せてください。 – pepyakin

+0

が質問に追加されました:) – Alexis

答えて

1

Androidプラットフォームは一般的に前方互換です。つまり、SDK 8(2.2)用のアプリを書くことができ、それは4.0で動作します。

UPDATE: は場合

+0

実際にアンドロイド4のnextButtonはsetButtonVisibilityが呼び出された時点でnullですが、アンドロイド2.2では呼び出されません。どのようにそれを可能にすることができますか? – Alexis

+0

Hm。ソースを使ってアプリプロジェクトを私に送ってもらえますか? – pepyakin

+0

最後に私はそれをデバッグしましたが、それはまだ変です:http://stackoverflow.com/questions/10088751/why-onfinishinflate-isnt-called-on-my-android-views-in-android-4 – Alexis

0

のAndroidは、下位互換性を持っているので、アンドロイド2.2のために書かれたアプリは、それが可能であるアンドロイド4

0

で動作するはずです。私はあなたがアンドロイド4にインストールしようとすると、それが正常にインストールされると思います。しかし、その逆を試みると、それは不可能です。アンドロイド4が提供する多くの先進的な変更が存在するためです。

関連する問題