在我的主要启动页面上,我对gridview中的项目进行了缩放动画。我注意到当我浏览我的UI时,我打算回到我的主页。用户界面有时会冻结和崩溃。我不知道是什么原因引起的。因为我确信代码中没有错误。 我已经粘贴了下面的堆栈跟踪
10-06 07:19:42.624: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 14K, 42% free 4021K/6919K, external 8275K/8764K, paused 146ms
10-06 07:19:42.864: I/dalvikvm-heap(436): Clamp target GC heap from 16.287MB to 16.000MB
10-06 07:19:42.885: D/dalvikvm(436): GC_FOR_MALLOC freed 61K, 43% free 3960K/6919K, external 8245K/8764K, paused 96ms
10-06 07:19:43.034: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 2K, 43% free 3957K/6919K, external 8245K/8764K, paused 143ms
10-06 07:19:43.254: I/dalvikvm-heap(436): Clamp target GC heap from 16.208MB to 16.000MB
10-06 07:19:43.254: D/dalvikvm(436): GC_FOR_MALLOC freed 9K, 43% free 3947K/6919K, external 8177K/8764K, paused 81ms
10-06 07:19:43.474: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 13K, 44% free 3934K/6919K, external 8159K/8764K, paused 122ms
10-06 07:19:43.674: I/dalvikvm-heap(436): Clamp target GC heap from 16.236MB to 16.000MB
10-06 07:19:43.674: D/dalvikvm(436): GC_FOR_MALLOC freed <1K, 44% free 3934K/6919K, external 8219K/8764K, paused 80ms
10-06 07:19:43.974: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 44% free 3934K/6919K, external 8219K/8764K, paused 217ms
10-06 07:19:44.295: I/dalvikvm-heap(436): Clamp target GC heap from 16.265MB to 16.000MB
10-06 07:19:44.295: D/dalvikvm(436): GC_FOR_MALLOC freed 0K, 44% free 3934K/6919K, external 8250K/8764K, paused 150ms
10-06 07:19:44.604: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 44% free 3934K/6919K, external 8250K/8764K, paused 215ms
10-06 07:19:44.884: I/dalvikvm-heap(436): Clamp target GC heap from 16.225MB to 16.000MB
10-06 07:19:44.884: D/dalvikvm(436): GC_FOR_MALLOC freed 11K, 44% free 3923K/6919K, external 8219K/8764K, paused 118ms
10-06 07:19:45.164: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 1K, 44% free 3922K/6919K, external 8219K/8764K, paused 176ms
10-06 07:19:45.405: I/dalvikvm-heap(436): Clamp target GC heap from 16.720MB to 16.000MB
10-06 07:19:45.414: D/dalvikvm(436): GC_FOR_MALLOC freed <1K, 44% free 3921K/6919K, external 8728K/8764K, paused 95ms
10-06 07:19:47.614: W/KeyCharacterMap(436): No keyboard for id -1
10-06 07:19:47.624: W/KeyCharacterMap(436): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
10-06 07:19:47.924: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 59K, 43% free 3960K/6919K, external 8266K/8764K, paused 149ms
10-06 07:19:48.134: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 0K, 43% free 3960K/6919K, external 8266K/8764K, paused 146ms
10-06 07:19:48.314: I/dalvikvm-heap(436): Clamp target GC heap from 16.758MB to 16.000MB
10-06 07:19:48.314: D/dalvikvm(436): GC_FOR_MALLOC freed 11K, 43% free 3949K/6919K, external 8739K/10787K, paused 96ms
10-06 07:19:48.864: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 2K, 43% free 3950K/6919K, external 8739K/10787K, paused 133ms
10-06 07:19:49.074: I/dalvikvm-heap(436): Clamp target GC heap from 16.778MB to 16.000MB
10-06 07:19:49.074: D/dalvikvm(436): GC_FOR_MALLOC freed 0K, 43% free 3950K/6919K, external 8758K/10787K, paused 80ms
10-06 07:19:49.394: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 43% free 3950K/6919K, external 8758K/10787K, paused 244ms
10-06 07:19:49.744: I/dalvikvm-heap(436): Clamp target GC heap from 16.786MB to 16.000MB
10-06 07:19:49.754: D/dalvikvm(436): GC_FOR_MALLOC freed 0K, 43% free 3950K/6919K, external 8766K/10787K, paused 171ms
10-06 07:19:50.024: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 43% free 3950K/6919K, external 8746K/10787K, paused 181ms
10-06 07:19:50.244: I/dalvikvm-heap(436): Clamp target GC heap from 16.759MB to 16.000MB
10-06 07:19:50.244: D/dalvikvm(436): GC_FOR_MALLOC freed <1K, 43% free 3950K/6919K, external 8739K/10787K, paused 134ms
10-06 07:19:53.534: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 15K, 43% free 3996K/6919K, external 8693K/10727K, paused 263ms
10-06 07:19:53.684: I/dalvikvm-heap(436): Clamp target GC heap from 16.766MB to 16.000MB
10-06 07:19:53.694: D/dalvikvm(436): GC_FOR_MALLOC freed 1K, 43% free 3995K/6919K, external 8702K/10727K, paused 49ms
10-06 07:21:14.895: W/KeyCharacterMap(436): No keyboard for id -1
10-06 07:21:14.895: W/KeyCharacterMap(436): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
10-06 07:21:15.217: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 301K, 39% free 4473K/7303K, external 8702K/10727K, paused 195ms
10-06 07:21:15.884: I/dalvikvm-heap(436): Clamp target GC heap from 17.286MB to 16.000MB
10-06 07:21:15.884: D/dalvikvm(436): GC_FOR_MALLOC freed 6K, 39% free 4466K/7303K, external 8762K/10727K, paused 287ms
10-06 07:21:16.174: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 191K, 42% free 4275K/7303K, external 8762K/10727K, paused 135ms
10-06 07:21:16.444: I/dalvikvm-heap(436): Clamp target GC heap from 17.106MB to 16.000MB
10-06 07:21:16.444: D/dalvikvm(436): GC_FOR_MALLOC freed 3K, 42% free 4272K/7303K, external 8772K/10727K, paused 121ms
10-06 07:21:16.704: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 0K, 42% free 4272K/7303K, external 8772K/10727K, paused 172ms
10-06 07:21:16.965: I/dalvikvm-heap(436): Clamp target GC heap from 16.934MB to 16.000MB
10-06 07:21:16.965: D/dalvikvm(436): GC_FOR_MALLOC freed 182K, 45% free 4089K/7303K, external 8780K/10727K, paused 123ms
10-06 07:21:17.164: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 0K, 45% free 4089K/7303K, external 8780K/10727K, paused 124ms
10-06 07:21:17.334: I/dalvikvm-heap(436): Clamp target GC heap from 16.944MB to 16.000MB
10-06 07:21:17.334: D/dalvikvm(436): GC_FOR_MALLOC freed 0K, 45% free 4089K/7303K, external 8789K/10727K, paused 63ms
10-06 07:21:17.514: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed 0K, 45% free 4089K/7303K, external 8789K/10727K, paused 102ms
10-06 07:21:17.624: I/dalvikvm-heap(436): Clamp target GC heap from 16.369MB to 16.000MB
10-06 07:21:17.624: D/dalvikvm(436): GC_FOR_MALLOC freed 3K, 45% free 4085K/7303K, external 8204K/10245K, paused 65ms
10-06 07:21:17.734: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 45% free 4085K/7303K, external 8204K/10245K, paused 105ms
10-06 07:21:17.894: I/dalvikvm-heap(436): Clamp target GC heap from 16.379MB to 16.000MB
10-06 07:21:17.894: D/dalvikvm(436): GC_FOR_MALLOC freed 0K, 45% free 4085K/7303K, external 8214K/10245K, paused 50ms
10-06 07:21:18.214: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 45% free 4086K/7303K, external 8214K/10245K, paused 243ms
10-06 07:21:18.555: I/dalvikvm-heap(436): Clamp target GC heap from 16.438MB to 16.000MB
10-06 07:21:18.555: D/dalvikvm(436): GC_FOR_MALLOC freed 0K, 45% free 4086K/7303K, external 8274K/10245K, paused 156ms
10-06 07:21:18.824: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 45% free 4086K/7303K, external 8274K/10245K, paused 181ms
10-06 07:21:19.044: I/dalvikvm-heap(436): Clamp target GC heap from 16.425MB to 16.000MB
10-06 07:21:19.044: D/dalvikvm(436): GC_FOR_MALLOC freed <1K, 45% free 4085K/7303K, external 8262K/10245K, paused 135ms
10-06 07:21:19.244: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 45% free 4085K/7303K, external 8262K/10245K, paused 171ms
10-06 07:21:19.794: I/dalvikvm-heap(436): Clamp target GC heap from 16.434MB to 16.000MB
10-06 07:21:19.804: D/dalvikvm(436): GC_FOR_MALLOC freed 0K, 45% free 4085K/7303K, external 8271K/10245K, paused 427ms
10-06 07:21:20.014: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 45% free 4086K/7303K, external 8271K/10245K, paused 138ms
10-06 07:21:20.234: I/dalvikvm-heap(436): Clamp target GC heap from 16.445MB to 16.000MB
10-06 07:21:20.234: D/dalvikvm(436): GC_FOR_MALLOC freed 0K, 45% free 4086K/7303K, external 8282K/10245K, paused 85ms
10-06 07:21:20.434: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 45% free 4086K/7303K, external 8282K/10245K, paused 129ms
10-06 07:21:20.584: I/dalvikvm-heap(436): Clamp target GC heap from 16.429MB to 16.000MB
10-06 07:21:20.584: D/dalvikvm(436): GC_FOR_MALLOC freed <1K, 45% free 4086K/7303K, external 8265K/10245K, paused 87ms
10-06 07:21:20.724: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 45% free 4086K/7303K, external 8265K/10245K, paused 127ms
10-06 07:21:20.924: I/dalvikvm-heap(436): Clamp target GC heap from 16.916MB to 16.000MB
10-06 07:21:20.934: D/dalvikvm(436): GC_FOR_MALLOC freed <1K, 45% free 4086K/7303K, external 8763K/10245K, paused 80ms
10-06 07:21:21.334: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 45% free 4086K/7303K, external 8753K/10245K, paused 166ms
10-06 07:21:21.504: I/dalvikvm-heap(436): Clamp target GC heap from 16.922MB to 16.000MB
10-06 07:21:21.504: D/dalvikvm(436): GC_FOR_MALLOC freed 0K, 45% free 4086K/7303K, external 8771K/10245K, paused 64ms
10-06 07:21:21.924: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 45% free 4086K/7303K, external 8771K/10245K, paused 339ms
10-06 07:21:22.424: I/dalvikvm-heap(436): Clamp target GC heap from 16.932MB to 16.000MB
10-06 07:21:22.424: D/dalvikvm(436): GC_FOR_MALLOC freed 0K, 45% free 4086K/7303K, external 8780K/10245K, paused 176ms
10-06 07:21:22.824: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 45% free 4086K/7303K, external 8780K/10245K, paused 315ms
10-06 07:21:23.034: I/dalvikvm-heap(436): Clamp target GC heap from 16.428MB to 16.000MB
10-06 07:21:23.044: D/dalvikvm(436): GC_FOR_MALLOC freed <1K, 45% free 4086K/7303K, external 8264K/10245K, paused 132ms
10-06 07:21:23.254: D/dalvikvm(436): GC_EXTERNAL_ALLOC freed <1K, 45% free 4086K/7303K, external 8255K/10245K, paused 185ms
10-06 07:21:23.314: I/dalvikvm(436): threadid=4: reacting to signal 3
10-06 07:21:23.514: I/dalvikvm(436): Wrote stack traces to '/data/anr/traces.txt'
10-06 07:21:23.795: I/dalvikvm-heap(436): Clamp target GC heap from 16.916MB to 16.000MB
10-06 07:21:23.795: D/dalvikvm(436): GC_FOR_MALLOC freed 0K, 45% free 4086K/7303K, external 8763K/10245K, paused 259ms
我的代码如下:
package com.example.rhemahealthcare;
import java.util.List;
import com.actionbarsherlock.R;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.example.customadapters.GridImageAdapter;
import com.example.database.DatabaseHelper;
import com.example.dbobject.DrugStallModel;
import com.example.dbobject.HospitalModel;
import com.example.dbobject.PatientModel;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.SubMenu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class HomeActivity extends SherlockActivity {
static final String[] menuString = new String[] { "Find Hospital","Drug Stalls","Emergency Calls","Medical Student","Nafdac","Health Gossip" };
//create the aleert dialog manager here
AlertDialogManager alert= new AlertDialogManager();
DatabaseHelper dbhelper = null;
Resources resource = null;
public static int THEME = R.style.Theme_Sherlock;
Context context = null;
// LinearLayout hint = null,hint1 = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView( com.example.rhemahealthcare.R.layout.homeactivity);
// loadApps();
resource = getResources();
context = HomeActivity.this;
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setIcon(android.R.color.transparent);
// hint = (LinearLayout)findViewById(R.id.sim);
// hint1 = (LinearLayout)findViewById(com.actionbarsherlock.R.id.hint1);
dbhelper = new DatabaseHelper(this);
GridView grid = (GridView) findViewById(com.example.rhemahealthcare.R.id.grid);
grid.setAdapter(new GridImageAdapter(HomeActivity.this,menuString,resource));
//adding the individual onClick event on the items in the grid
grid.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id){
// TODO Auto-generated method stub
//TextView v = ((TextView) view.findViewById(R.id.griditemText));
//String textValue = v.getText().toString();
String selectMenutext = (String) ((TextView) view.findViewById( com.example.rhemahealthcare.R.id.griditemText)).getText();
if(selectMenutext.equals("Find Hospital")){
Intent intent = new Intent(HomeActivity.this,HospitalsInRegion.class);
startActivity(intent);
}
else if(selectMenutext.equals("Drug Stalls")){
Intent intent = new Intent(HomeActivity.this,DrugStallsInRegionActivity.class);
startActivity(intent);
}
else if(selectMenutext.equals("Health Gossip")){
Intent intent = new Intent(HomeActivity.this,PreHealthGossipActivity.class);
startActivity(intent);
}
else if(selectMenutext.equals("Medical Student")){
Intent intent = new Intent(HomeActivity.this,MedicalStudentActivity.class);
startActivity(intent);
}
else if(selectMenutext.equals("Emergency Calls")){
Intent intent = new Intent(HomeActivity.this,PreEmergencyActivity.class);
startActivity(intent);
}
else if(selectMenutext.equals("Nafdac")){
Intent intent = new Intent(context,NafdacActivity.class);
startActivity(intent);
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getSupportMenuInflater();
inflater.inflate(com.example.rhemahealthcare.R.menu.homemenu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
int itemID = item.getItemId();
switch(itemID){
//This is going to work for the action bar back button
case android.R.id.home:
Toast.makeText(getApplicationContext(),"Back button clicked", Toast.LENGTH_SHORT).show();
break;
case com.example.rhemahealthcare.R.id.lasthospital:
this.displayLastHospitalVisited();
break;
case com.example.rhemahealthcare.R.id.lastpharmacy:
this.displayLastDrugStallVisited();
break;
case com.example.rhemahealthcare.R.id.medicalcard:
this.displayMedicalCard();
break;
case com.example.rhemahealthcare.R.id.settings:
this.displayAppSettings();
break;
case com.example.rhemahealthcare.R.id.help:
this.displayHelp();
break;
case com.example.rhemahealthcare.R.id.about:
this.displayAbout();
break;
case com.example.rhemahealthcare.R.id.maplocation:
this.displayMapLocation();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
//This method is going to be used too display the health Gossip page
private void displayMapLocation(){
//Intent intent = new Intent(context,HealthGossipActivity.class);
//startActivity(intent);
}
//This method is goign to be used to display the last hospital visited by the patient
private void displayLastHospitalVisited(){
//we would have to check the database and see if the user as visited a hospital
if(this.ReturnHospitalName() == null){
String errormsg = resource.getString(com.example.rhemahealthcare.R.string.notvisitedHospital);
Toast.makeText(context, errormsg,Toast.LENGTH_LONG).show();
}
else{
//Toast.makeText(context,"Last hospital selected ",Toast.LENGTH_LONG).show();
Intent intent = new Intent(context,HospitalMenuActivity.class);
startActivity(intent);
}
}
//This method is going to be used to display the last phamercitical firm visited
private void displayLastDrugStallVisited(){
//we would have to check the database and see if the user as visited a drug stall
if(this.ReturnDrugStallName() == null){
String errormsg = resource.getString(com.example.rhemahealthcare.R.string.notvisiteddrugstall);
Toast.makeText(context, errormsg, Toast.LENGTH_LONG).show();
}
else{
Intent intent = new Intent(context,DrugStallMenuActivity.class);
startActivity(intent);
}
}
//This method is going to be used to display settings
private void displayAppSettings(){
Intent intent = new Intent(context,SettingsActivity.class);
startActivity(intent);
}
//This method is going to display the Help Activity
private void displayHelp(){
Intent intent = new Intent(context,HelpActivity.class);
startActivity(intent);
}
private void displayAbout(){
Intent intent = new Intent(context,AboutActivity.class);
startActivity(intent);
}
//This method is going to display the patient medical card
private void displayMedicalCard(){
PatientModel patient = dbhelper.ReturnPatientDetails(1);
Intent intent = new Intent(HomeActivity.this,PatientMedicalCardActivity.class);
intent.putExtra("phone",patient.getPhone());
intent.putExtra("email",patient.getEmail());
startActivity(intent);
}
//We are going to collect the drug stall name from the database
private DrugStallModel ReturnDrugStallName(){
String drugstallname= new String();
DrugStallModel drugstall = this.dbhelper.ReturnLastVisitedDrugStall(1);
return drugstall;
}
//We would collect the name of the hospital from the database
private HospitalModel ReturnHospitalName(){
String hospitalName = new String();
HospitalModel hospital = this.dbhelper.ReturnLastVisitedHospitalDetails(1);
return hospital;
}
}
我的布局的xml如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lineargrid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/sim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:background="@drawable/hintlinearrect"
android:orientation="horizontal"
android:padding="5dp" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:src="@drawable/hint" />
<TextView
android:id="@+id/chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hintText"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/red" />
</LinearLayout>
<LinearLayout
android:id="@+id/hint1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:layout_marginTop="10dp"
android:background="@drawable/hintlinearrect"
android:orientation="horizontal"
android:padding="5dp"
android:visibility="gone" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:src="@drawable/hint" />
<TextView
android:id="@+id/chat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nointernet"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/red" />
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/detailsicon" />
</LinearLayout>
<GridView
android:id="@+id/grid"
style="@style/gridViewStyle"
android:layout_width="fill_parent"
android:layout_height="370dp"
android:clickable="true"
android:columnWidth="100dp"
android:gravity="center"
android:layoutAnimation="@anim/layout_wave_scale"
android:numColumns="auto_fit"
android:stretchMode="columnWidth" />
</LinearLayout>
<gridLayoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:rowDelay="75%"
android:columnDelay="0%"
android:directionPriority="none"
android:animation="@anim/wave_scale" />