English 中文(简体)
如果变化得太快,就会恢复方向变化。
原标题:Saving string on orientation change FC s app if changed too quickly

我的麻烦使朝向上的扼杀发生了变化。 I ve Trial using onSaveInstanceState()/onResshopInstanceState() and on RetainNonConfiguration Instance()/get LastNonConfiguration Instance( with no luck.

I have:

@Override
public String onRetainNonConfigurationInstance(){
    final String savedType = currentType;
    return savedType;
}

www.un.org/chinese/sc/presidency.asp 我有:

currentType = (String) getLastNonConfigurationInstance();

这一吨位对我来说仍然有效, Current Type在方向变化之后始终为null<>.>。 任何建议?


Revision


因此,这是我目前已经做的事,它仍然没有发挥作用:

@Override
protected void onSaveInstanceState(Bundle outState){
    outState.putString("savedType", currentType);
    super.onSaveInstanceState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState){
    currentType = savedInstanceState.getString("savedType");
    super.onRestoreInstanceState(savedInstanceState);
}

I ve tried putting the super method calls at the beginning and end of each method in every combination I could think of but am still getting a NullPointerException for currentType when the view is created again.


Also


在迪亚洛,我不敢肯定这是否与它有任何关系,但认为这可能是一种有用的信息。



Partial Solution/Partial New Question



因此,我只想从事这项工作。 在生命周期结束时,如果再需要变数t,则用一种方法填写了<代码> 当前Typenull。 这一点现在已经消失了。 屏幕将成功地改变方向,但如果在连续两次之间变换得太快,就会起推波助澜的作用。 这是我用来在这个国家开展工作的:

班级:

private String currentType;

在<代码>末尾 我有:

currentType = (String) getLastNonConfigurationInstance();

之后:

@Override
public Object onRetainNonConfigurationInstance() {
    final String s = currentType;
    return s;
}

如果取向没有变化,则会进行罚款,然后迅速重新调整。 我愿确定这一点,因为各部和零售店正在使用/将使用这一产品,我可以看到人们会放弃这一产品,这将导致产生一种促进作用(把它放到我的库中测试)。 我只剩下一根str子,而我stor忙却不忘。 对这一新情况提出的任何建议?

最佳回答

So I got this working somewhat like I wanted. There was a statement buried in a method that set currentType to null towards the end of the life cycle when the variable wouldn t be needed again. That s now out of the way. The screen will successfully change orientations but if it s changed between the two successively too quickly it will FC. This is what I used to get it working in this state:

Class Field:

private String currentType;

在条约结束时,我已经:

currentType = (String) getLastNonConfigurationInstance();

之后:

@Override
public Object onRetainNonConfigurationInstance() {
    final String s = currentType;
    return s;
}

如果取向没有变化,则会进行罚款,然后迅速重新调整。 提出这个新难题,

问题回答

你们是否试图把它放入一个布局?

private static final String CURRENT_TYPE = "currentType";
private static final String DEFAULT_TYPE = "defaultType";
@Override
protected void onSaveInstanceState (Bundle outState) {
  outState.putString(CURRENT_TYPE, currentType);
  super.onSaveInstanceState(outState);
}
@Override
protected void onCreate (Bundle savedInstanceState) {
  ...
  currentType = (savedInstanceState == null)? null : 
        savedInstanceState.getString(CURRENT_TYPE, DEFAULT_TYPE);
  ...
}




相关问题
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 ...

热门标签