我是android.I的新手,我尝试过使用一些开源代码来开发一个应用程序。该应用程序使用画廊中的图像,然后将其带入imageview,我们对图像进行一些操作。
我需要的是,该应用程序应该开始一些默认的图像已经进入imageview..then我会添加一些按钮,以选择从画廊图像稍后。我不明白这里的工作流程。如果有人能指导我,那就太好了。
这是我的代码主activity.which还包含闪屏。
public class Main extends Activity {
static final String PREFS_FILE = "image_edit";
/** The URI of the Image to display. */
private int _wait;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main_screen);
_wait = 1000;
imageUri = null;
}
@Override
protected void onResume() {
super.onResume();
if (_wait != 0) {
new CountDownTimer(_wait, _wait) {
@Override
public void onFinish() {
if (imageUri != null) {
Intent viewActivity = new Intent(Main.this, Viewer.class);
viewActivity.putExtra("image", imageUri);
startActivity(viewActivity);
} else {
startActivityForResult(newIntent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI),0);
}
}
@Override
public void onTick(long millisUntilFinished) {
}
}.start();
_wait = 0;
} else {
if (imageUri != null) {
Intent viewActivity = new Intent(this, Viewer.class);
viewActivity.putExtra("image", imageUri);
startActivity(viewActivity);
} else {
startActivityForResult(newIntent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), 0);
}
}
}
@Override
protected void onPause() {
super.onPause();
imageUri = null;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
imageUri = data.getData();
} else {
System.exit(0);
Log.e("result", "BAD");
}
}
}然后,从这里拍摄的图像转到名为Viewer activity的下一个活动,其onresume为
protected void onResume() {
super.onResume();
mHandler = new Handler();
mPreferences = this.getSharedPreferences(Main.PREFS_FILE, 0);
setContentView(R.layout.nothing);
// Inflate all the views.
int orientation = getResources().getConfiguration().orientation;
basicInit(orientation);
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
initPortrait();
} else {
initLandscape();
}
Intent intent = getIntent();
Uri imageURI = null;
Log.e("URI:", intent.getData() + "");
if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_SEND)) {
Bundle extras = intent.getExtras();
if (extras.containsKey(Intent.EXTRA_STREAM)) {
imageURI = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);
}
} else if (intent.getAction() != null && intent.getAction().equals(Intent.ACTION_VIEW)) {
imageURI = intent.getData();
} else {
imageURI = (Uri) intent.getParcelableExtra("image");
}
addImage(imageURI);
addDraggableImages();
_updateImageTask = new UpdateImage(mRelative, mHandler);
}因此,我尝试在主视图中执行此操作,其中
if(wait !=0){}
else{
startActivity(new Intent(Main.this, Viewer.class));
}但这并不是work..error is runtimeexception
所以如果有人指导me..Thanks会很有帮助
发布于 2013-07-08 19:47:39
正如您在MainActivity的onResume()方法中看到的,它首先将转到else部分,即startActivityForResult,它将打开一个图库,并要求您拾取一张图像。
您可以在main_screen.xml中简单地创建一个按钮,而不是将其放入onResume中
然后在该按钮的onclickListener中实现此功能。
要在默认情况下查看图像,可以在xml标记中放入: android:src="@drawable/imageFile“
这对你来说有意义吗?
https://stackoverflow.com/questions/17448974
复制相似问题