我正在尝试编写一个Activity,它会为长时间运行的操作生成AsyncTask,并定期将状态更新发布回Activity.我想确保AsyncTask正确地存在屏幕旋转或其他破坏条件,如OOM.
我已经在android-developers列表中读到了这个帖子,这反过来又促使我实现了这个实现,这几乎就是我所需要的.但是,我的AsyncTask的最后一步是从内容解析器中删除一些数据.非常重要的是不要跳过此步骤,因为数据是敏感的,在正常情况下不应留在手机上.但是,ContentResolvers来自Contexts,在本例中是Activity,使用此方案,当AsyncTask准备好删除时,Activity可能为null.
从AsyncTask构造的Activity获取ContentResolver并保持活动的生命周期是否安全?如果没有,我该怎么办才能处理这个案子?
我目前正在制作非常密集的动态壁纸,并且不能很好地处理屏幕旋转.
事实上,壁纸被破坏并显示一个空白的屏幕而没有调用onSurfaceChanged!
这是我在onSurfaceChanged方法中的内容:
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
// TODO Auto-generated method stub
super.onSurfaceChanged(holder, format, width, height);
mRatio = (float) width / height;
if (mRatio > 1) {
orientation = 0;
}
if (mRatio < 1) {
orientation = 1;
}
setRunning(true);
Log.i(TAG, "Screen Rotation...");
mHandle.post(r);
}
Run Code Online (Sandbox Code Playgroud)
我很肯定这个方法没有被调用,因为没有日志消息.
为什么会发生这种情况以及处理屏幕旋转的一些技巧是什么?可能是我的动态壁纸如此密集,无法调用空白?
此外,也没有调用onVisibilityChanged,当我在模拟器上打开应用程序时,没有日志消息:
@Override
public void onVisibilityChanged(boolean visible) {
// TODO Auto-generated method stub
super.onVisibilityChanged(visible);
if (visible) {
setRunning(true);
Log.i(TAG, "Visible...");
mHandle.postDelayed(r, 2000);
} else { …Run Code Online (Sandbox Code Playgroud) 我有一个GLKit基于应用程序,显示一些简单的对象.
一切正常,除了屏幕旋转,在此期间GLKView不更新(-drawRect:未调用).因此,在旋转期间,投影矩阵不会根据动态变化的屏幕尺寸进行更新,并且对象看起来很糟糕(拉伸).
在下面的链接中,Microsoft描述了两种限制平板电脑上应用程序屏幕旋转的方法.
http://msdn.microsoft.com/en-ca/library/windows/apps/hh700342.aspx
发生的事情是德尔福的(XE3)TRibbon不能很好地处理旋转.它往往会挂起来.
正如所料,MS网站描述了如何从MS开发产品中做到这一点.我不知道如何在我的Delphi项目中做到这一点.
方法1:
将此添加到您的appxmanifest文件:
<InitialRotationPreference>
<Rotation Preference="landscape"/>
<Rotation Preference="landscapeFlipped"/>
</InitialRotationPreference>
Run Code Online (Sandbox Code Playgroud)
我还没有找到appxmanifest应该成为应用程序的一部分,所以我可以在delphi中执行此操作.
方法2:
用代码调用它:
Windows.Graphics.Display.DisplayProperties.AutoRotationPreferences =
Windows.Graphics.Display.DisplayOrientations.Landscape;
Run Code Online (Sandbox Code Playgroud)
要将其迁移到delphi,我需要知道API DLL信息,以便我可以做类似的事情.
有任何想法吗?
是否有一个COM对象或DLL可以让我们访问它?
我正在膨胀一些EditTexts并将它们添加到LinearLayout:
private void setupCommentViews(){
int i = 0;
Iterator<CommentInformation> iterator = commentInformations.iterator();
while(iterator.hasNext()) {
i++;
View v = LayoutInflater.from(context).inflate(R.layout.comment_row_item, commentsContainer, false);
EditText commentField = (EditText)v.findViewById(R.id.comment);
CommentInformation commentInformation = iterator.next();
final String uniqueId = commentInformation.getUniqueId();
String currentCommentText = comments.get(uniqueId);
if(currentCommentText != null) {
Log.v("into","Setting old text: "+currentCommentText);
commentField.setText(currentCommentText);
} else {
Log.v("into","Setting empty text: "+i);
commentField.setText("Setting empty text: "+i);
}
commentField.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override …Run Code Online (Sandbox Code Playgroud) android android-layout screen-rotation android-edittext layout-inflater
我有一个简单的应用程序,包含一个视图控制器.我从Xcode 7 GM单视图应用程序模板开始,但随后删除了主故事板,并设置了我的视图控制器,如下所示:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let vc = ViewController()
window = UIWindow(frame: UIScreen.mainScreen().bounds)
window!.rootViewController = vc
window!.makeKeyAndVisible()
return true
}
Run Code Online (Sandbox Code Playgroud)
在我的信息plist中,我在支持的界面方向下指定了所有方向,并且应用程序在iPad上旋转到所有方向.
但是,在我的简单视图控制器中,永远不会调用shouldAutorotate()和supportedInterfaceOrientations()方法.这是一个问题,因为我正在尝试启用和禁用自动旋转的UI控件.什么可能阻止这些方法被调用?
这里的示例项目(需要Swift 2)
¹non-UINavigationController
我有一个视图控制器显示一个带有 UITextView 的视图,我想在键盘出现时调整视图的大小,以便键盘不会覆盖 UITextView。我几乎在所有情况下都能正常工作。据我所知,我仍然在 iPad 上看到一些奇怪的东西,只有当视图控制器出现在 ModalPresentationStyleFormSheet 中时,而且只有在 LandscapeRight 方向上。
我的视图控制器的 -keyboardWillShow 的相关部分:
// We'll store my frame above the keyboard in availableFrame
CGRect availableFrame = self.view.frame;
// Find the keyboard size
NSDictionary *userInfo = [notification userInfo];
NSValue keyboardFrameScreenValue = userInfo[UIKeyboardFrameBeginUserInfoKey];
CGRect keyboardFrameScreen = [keyboardFrameScreenValue CGRectValue];
CGRect keyboardFrame = [self.view convertRect:keyboardFrameScreen fromView:nil];
CGSize keyboardSize = keyboardFrame.size;
// Figure out how much of my frame is covered by the keyboard
CGRect screenBounds = [self.view convertRect:[UIScreen mainScreen].bounds
fromView:nil];
CGRect myBoundsScreen = [self.view …Run Code Online (Sandbox Code Playgroud) keyboard screen-rotation modalviewcontroller ios uimodalpresentationstyle
我想在屏幕旋转期间保留复杂的java对象,所以我使对象Parcelable并实现了必要的方法:
然后在Fragment的onSaveInstanceState中我保存了Parcelable:
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable("myObject", myObject);
}
Run Code Online (Sandbox Code Playgroud)
并在Fragment的onCreate中得到了我的对象:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyObject myObject = savedInstanceState.getParcelable("myObject");
}
Run Code Online (Sandbox Code Playgroud)
这非常有效.
然后我做了一个测试:
当我运行应用程序时,我得到了完全相同的结果!我得到了一个包含所有适当值的对象.
这为何有效?Parcelable是否自动创建"Parcelable对象"?
我尝试在网络视图中使用react-native-orientation,使其成为唯一可以旋转的视图。
import React, {useEffect} from 'react';
import { WebView } from 'react-native-webview';
import Orientation from "react-native-orientation"
export function GameWebViewScreen({navigation}) {
const link = ****
useEffect(() => {
Orientation.unlockAllOrientations();
}, [])
return <WebView source={{uri: link}}/>
}
Run Code Online (Sandbox Code Playgroud)
我在 unlockAllOrientations 调用中收到 TypeError: null in not an object 。有谁知道这是一个问题,因为我还没有按照此处的说明中的说明配置本机文件,因为我还没有访问它们的权限?
我也尝试使用类组件并得到相同的结果。
我也欢迎有关控制单个视图旋转的库的任何其他建议。
我附上一个焦点侦听器,到EditText时就OnCreateView在我的Fragment。如果EditText获得焦点,则通知侦听器。到目前为止一切顺利,但在屏幕旋转后,当焦点恢复到新的Fragment. 有什么好的做法可以区分由于配置更改引起的侦听器通知和由于真实的人工交互引起的通知吗?或者在由于配置更改而导致焦点更改后根本不通知侦听器?
screen-rotation ×10
android ×5
ios ×3
delphi ×1
fragment ×1
glkit ×1
glkview ×1
ios9 ×1
java ×1
keyboard ×1
parcelable ×1
react-native ×1
ribbon ×1
rotation ×1
tablet ×1
typescript ×1