在我的Android应用程序中,我正在显示图像&主要活动上的文本,切换到另一个活动(杀死主要活动),然后切换回主要活动,但添加从闪存中提取的新图像和文本。
在启动时,我的活动按预期工作,但是当我从主活动切换到另一个活动时,然后回到主活动,没有显示图像或文本。
我试图使文本和图片无效,但似乎仍然没有显示任何图像/文字。
修改
我可以从Page_Activity转到Gallery_Activity,但当我尝试从Gallery_Activity返回Page_Activity时,我无法更改XML中定义的任何ImageViews / TextView。
我提供了以下活动之间切换的相关代码。
private void display_page(int pg_num)
{
image_overlay = Bitmap.createBitmap(canvas_width, canvas_height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image_overlay);
int yCo = 0;
for(int yCount=0; yCount<num_y_tiles; yCount++){
int xCo = 0;
for(int xCount=0; xCount<num_x_tiles; xCount++){
//code to get bufferedimage from flash (works)
old_tiles[xCount][yCount] = bufferedimage;
canvas.drawBitmap(old_tiles[xCount][yCount], xCo, yCo, null);
xCo += TILE_WIDTH;
}
yCo+= TILE_HEIGHT;
}
imageview_overlay.setImageBitmap(image_overlay);
imageview_overlay.setVisibility(View.VISIBLE);
imageview_overlay.invalidate();
textview_page_number.setText("Page " + page_number);
textview_page_number.invalidate();
}
/*
*Inside the click listener to go to Gallery_Activity
*/
Intent intent = new Intent(v.getContext(), Gallery_Activity.class);
boolean is_books_empty = true;
String[] stringArray;
ArrayList<Integer> images = new ArrayList<Integer>();
int number = R.drawable.gallery_book1;
for(int i=0; i<stringArray.length; i++){
images.add(i, R.drawable.gallery_book1);
}
intent.putExtra("StringArray", );
intent.putIntegerArrayListExtra("BookImages", images);
startActivity(intent);
finish();
public class Gallery_Activity extends Activity{
public String[] names;
public ArrayList<Integer> images;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gallery);
images = getIntent().getIntegerArrayListExtra("BookImages");
names = getIntent().getStringArrayExtra("StringArray");
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter (new ImageAdapter(this, names, images));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Intent intent = new Intent(v.getContext(), Page_Activity.class);
String book_names = names[position];
intent.putExtra("BookName", book_names);
startActivity(intent);
}
});
}
}