Android 当我们返回到以前的活动时,如何达到它的状态
我有一个图像视图和两个按钮活动中的Gallery和Next。当我按Gallery按钮时,我可以从Gallery中选择一个图像,并将该图像作为位图分配给图像视图。当我按Next按钮时,我将转到其他活动,我将使用intent从此活动转到第一个活动。然后,我在第一个活动中未找到从库中选择的图像。即,一旦调用了第一个活动的创建方法。但我想在返回第一个活动时显示第一个带有图像的活动。请帮助我 这是我的主要活动Android 当我们返回到以前的活动时,如何达到它的状态,android,android-intent,android-bitmap,Android,Android Intent,Android Bitmap,我有一个图像视图和两个按钮活动中的Gallery和Next。当我按Gallery按钮时,我可以从Gallery中选择一个图像,并将该图像作为位图分配给图像视图。当我按Next按钮时,我将转到其他活动,我将使用intent从此活动转到第一个活动。然后,我在第一个活动中未找到从库中选择的图像。即,一旦调用了第一个活动的创建方法。但我想在返回第一个活动时显示第一个带有图像的活动。请帮助我 这是我的主要活动 import android.app.Activity; import android.co
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity{
ImageView iv;
TextView tv;
int width=320,height=480;
Button text,gallery;
private static int RESULT_LOAD_IMAGE = 1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv=(ImageView)findViewById(R.id.imageView1);
tv=(TextView)findViewById(R.id.textView2);
text=(Button)findViewById(R.id.button2);
gallery=(Button)findViewById(R.id.button3);
final Bitmap pf1 = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
Bitmap scaled=Bitmap.createScaledBitmap(pf1, width, height, true);
iv.setImageBitmap(scaled);
//Intent i=getIntent();
//String value=i.getStringExtra("mydata");
//tv.setText(value);
iv.setOnTouchListener(new myTouchListener());
text.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent=new Intent(getApplicationContext(),FrmActivity.class);
startActivity(intent);
}
});
gallery.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RESULT_LOAD_IMAGE);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
//ImageView imageView = (ImageView) findViewById(R.id.imgView);
//Bitmap bitmap = Bitmap.createBitmap(pic.getWidth(), pic.getHeight(), Bitmap.Config.RGB_565);
Bitmap bitmap1=BitmapFactory.decodeFile(picturePath);
Bitmap scaled=Bitmap.createScaledBitmap(bitmap1, width, height, true);
iv.setImageBitmap(scaled);
iv.setOnTouchListener(new myTouchListener());
}
}
public void onResume()
{
super.onResume();
}
}
我的第二项活动是
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class FrmActivity extends Activity {
Button mButton;
EditText mEdit;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_frm);
mButton = (Button)findViewById(R.id.button1);
mEdit = (EditText)findViewById(R.id.editText1);
mButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent=new Intent(getApplicationContext(),MainActivity.class);
//intent.putExtra("mydata",mEdit.getText().toString());
startActivity(intent);
}
});
}
}
我的主xml文件是
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher"
android:scaleType="matrix" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_parenthetical="true"
android:layout_centerVertical="true"
android:layout_marginLeft="94dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="49dp"
android:text="Text" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_alignParentTop="true"
android:text="Gallery" />
</RelativeLayout>
我的第二个布局是
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginTop="23dp"
android:text="@string/input_lable"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#0099FF" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView2"
android:layout_toRightOf="@+id/textView2"
android:background="#CCCCCC"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView2"
android:layout_marginTop="20dp"
android:background="#0099FF"
android:text="@string/sub"
android:textColor="#FFFFFF" />
</RelativeLayout>
在代码中重写onResume方法。提供一些代码,说明如何使用startActivity或StartActivityForresult启动图库,因为当您返回到第一个活动时,会调用onResume函数,因此您必须在此方法中管理映像。onResume方法中要覆盖哪些内容?您选择的映像可能是您的文件路径或从中获得的任何内容您以前的活动。我不知道你想要达到什么目标,我怎么能说什么呢?你在活动中要做什么?点击“下一步”按钮,从第一个活动转到下一个活动。