2
我正在使用Titanium 3.1并针对Android 3.0及更高版本进行开发。如何在Titanium开发的Android应用程序中保存实例状态?
我的应用程序有一个视图,当点击时询问您是否要拍照或从图库中选择图像。当我选择从相机拍摄照片时,相机显示没有问题,我可以拍摄照片,问题是在拍摄照片并选择使用照片后,我的应用程序从头开始恢复,而不是返回到之前选择拍照前的状态。
当我检查logcat的我看到这行:
I/TiRootActivity(24120): (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
看来我的应用程序的状态不会被保存,但我不知道为什么。我会诚实地说,这是我第一次开发一款应用程序,该应用程序会转到相机应用程序,拍摄照片并返回到应用程序。以前我曾在Titanium中使用Intents,并且在退出使用后退按钮用Intent打开的应用程序后,我已能够返回到我的应用程序的正确状态。
这是我用它来打开摄像头的代码:
var globalBabyPicture = Titanium.UI.createImageView({
image:imagesPath + "kinedu_0027_ic_camara.png",
width:75,
});
var photoOptionsViewFromCamera = Ti.UI.createView({
width:Ti.Platform.displayCaps.platformWidth,
height:44,
left:0,
top:1*44,
backgroundColor:"transparent"
});
var photoOptionsViewFromCameraLabel = Ti.UI.createLabel({
text:"from camera",
font:{fontSize:14, fontFamily:"Arial Rounded MT Bold"},
color:"#368cd6"
});
photoOptionsViewFromCamera.add(photoOptionsViewFromCameraLabel);
photoOptionsViewFromCamera.addEventListener("touchstart", function(e){
var animateTouchStart = Ti.UI.createAnimation({backgroundColor:"#AFD1DE", duration:150});
photoOptionsViewFromCamera.animate(animateTouchStart);
});
//********* this is the code that triggers the camera to take the picture
photoOptionsViewFromCamera.addEventListener("touchend", function(e){
var animateTouchEnd = Ti.UI.createAnimation({backgroundColor:"transparent", duration:150});
photoOptionsViewFromCamera.animate(animateTouchEnd);
animateTouchEnd.addEventListener("complete", function(e){
Ti.Media.showCamera({
success : function(event) {
var tmp = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, ('baby_temp.png'));
tmp.write(event.media);
var blob = tmp.read();
Ti.App.fireEvent("changePicture");
},
cancel : function() {
},
error : function(error) {
var message;
if (error.code == Ti.Media.NO_CAMERA) {
message = 'Device does not have camera capabilities';
} else {
message = 'Unexpected error: ' + error.code;
}
Ti.UI.createAlertDialog({
title : 'Camera',
message : message
}).show();
},
saveToPhotoGallery : false,
allowEditing : true,
mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO]
});
});
});
Ti.App.addEventListener("changePicture", function(e){
var tmp = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, ('baby_temp.png'));
var blob = tmp.read();
var animationChange = Ti.UI.createAnimation({opacity:0, duration:200});
babyImage.animate(animationChange);
var animationChangeCompleted = Ti.UI.createAnimation({opacity:1, duration:200});
animationChange.addEventListener("complete", function(e){
babyImage.setWidth(100);
var image = blob.imageAsThumbnail(150);
babyImage.setImage(image);
babyImage.animate(animationChangeCompleted);
});
});
我检查,并成功回调从来没有,我认为这是因为应用程序从一开始恢复,显示应用程序启动画面。
如何确保在拍摄照片后,应用程序返回到前一个视图,而不必从头开始恢复应用程序?
如果您的应用展示飞溅可能崩溃,而你与恢复从一开始就应用混淆了。 我建议从adb中检查logcat以及Titanium控制台,并在这里粘贴日志。 – Dragon