开发者

Android: passing data between views

In my Android app, I have two custom view classes - PortraitClass and LandscapeClass. They both do the same thing. On running the app, the view class fetches some pictures from an SDCard and then maniputlates (skew etc) and displays them. The only difference between the two classes is that the layout of pictures is slightly different on the screen.

I have two display.xml files (one under layout folder and the other under layout-land). The one under the layout folder adds Portrait and the other adds the Landscape class.

On orientation change, I would like to send information (picture numbers and few bitmaps) from one class to another so I won't have to fetch all the bitmaps again and also so that I display the ones that were being displayed.

I find the parcelable thing kind of confusing. I tried following this_example, but I noticed that in onRestoreInstance, the Parcelable has null for the "mSuperState" and I get a classCa开发者_如何学编程stException @ "SavedState ss = (SavedState)state". The integer (picture number) that I am trying to pass is there. I am not sure what I am doing wrong.


You could use a global singleton in the Application class. For example an "AssetManager" is available here:

public class YourApplication extends Application {

    public AssetManager assetManager = new AssetManager();

    @Override
    public void onCreate() 
    {
        super.onCreate();
    }
}

You can then call it from another activity:

 YourApplication application = ((YourApplication ) this.getApplication());
 application.assetManager.someFunction();


Not sure if this is what you are looking for but my stuff always works in orientation change with onCreate(Bundle savedInstanceState). Mine is all text in edit text boxes though so I am not sure how it would work for you.

Also check this out about midway down under "Persisting State Information During Configuration Change" http://www.devx.com/wireless/Article/40792/1954

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜