Reputation: 1
I'm some what new to Android. My application crash when user return from long idle. I have read the Android app life cycle and debug the app. It looks like my app crash at the onCreate method when user come back from long idle. Below is my onCreate code. It get Global Variable (CustomerName) which is set from previous activity. Then, pull data from SQLLite base on the CustomerName to display data. I think the Android VM has killed the process when user return to the activity, but I thought the process should work when the onCreate is call again. Any help would be greatly appreciated.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_report_review);
intialize();
adddynamiccheckboexes();
//Initialize
metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
panelWidth = (int) ((metrics.widthPixels)*0.75);
headerPanel = (RelativeLayout) findViewById(R.id.header);
headerPanelParameters = (LinearLayout.LayoutParams) headerPanel.getLayoutParams();
headerPanelParameters.width = metrics.widthPixels;
headerPanel.setLayoutParams(headerPanelParameters);
menuPanel = (RelativeLayout) findViewById(R.id.menuPanel);
menuPanelParameters = (FrameLayout.LayoutParams) menuPanel.getLayoutParams();
menuPanelParameters.width = panelWidth;
menuPanel.setLayoutParams(menuPanelParameters);
slidingPanel = (LinearLayout) findViewById(R.id.slidingPanel);
slidingPanelParameters = (FrameLayout.LayoutParams) slidingPanel.getLayoutParams();
slidingPanelParameters.width = metrics.widthPixels;
slidingPanel.setLayoutParams(slidingPanelParameters);
CustomerName = ((GlobalVariables) this.getApplication()).getSomeVariable();
//Check to see if CustName exist. If not, go to Main screen
CustomerName.trim();
if (CustomerName.equals("null") || CustomerName.equals("")){
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
return;
}
assessHelper = new AssessmentDBAdaptor(this);
assessHelper.open();
String fCustomerName = CustomerName;
fCustomerName = fCustomerName.replaceAll("''", "'");
fCustomerName = fCustomerName.replaceAll("'", "''");
Cursor AssessInfo = assessHelper.fetchAssessmentByExactName(fCustomerName);
if (AssessInfo.moveToFirst()){
City = AssessInfo.getString(AssessInfo.getColumnIndexOrThrow("City")).toString();
State = AssessInfo.getString(AssessInfo.getColumnIndexOrThrow("State")).toString();
AssessDate = AssessInfo.getString(AssessInfo.getColumnIndexOrThrow("CreatedDate")).toString();
TA_Name = AssessInfo.getString(AssessInfo.getColumnIndexOrThrow("PresentedBy")).toString();
CustEmail = AssessInfo.getString(AssessInfo.getColumnIndexOrThrow("Email")).toString();
}else{
Toast.makeText(getApplicationContext(), "Error: Unable to retrieve Assessment Information", Toast.LENGTH_SHORT).show();
}
ppHelper = new DBPlantPhoto(this);
ppHelper.open();
fCustomerName = CustomerName;
fCustomerName = fCustomerName.replaceAll("''", "'");
fCustomerName = fCustomerName.replaceAll("'", "''");
Cursor sPP = ppHelper.fetchPlantPhotoByAssessment(fCustomerName);
if (sPP.moveToFirst()){
FileName = sPP.getString(sPP.getColumnIndexOrThrow("FileName")).toString();
}else{
//Toast.makeText(getApplicationContext(), "Error: Unable to retrieve Plant Photo", Toast.LENGTH_SHORT).show();
}
//Tien
dbBulletHelper = new DBSlideBullet(this);
dbBulletHelper.open();
fCustomerName = CustomerName;
fCustomerName = fCustomerName.replaceAll("''", "'");
fCustomerName = fCustomerName.replaceAll("'", "''");
Cursor cAssess = dbBulletHelper.fetchSlideInfobyCateandAssess("Best Practice Summary", fCustomerName);
if (cAssess.moveToFirst()){
//Exist
}else{
//Not Exist
DBSlideBullet entry = new DBSlideBullet(ReportReview.this); //call upon database pass in context of this class
entry.open();
entry.CreateEntry("Best Practice Summary", "Best Practice Summary", "1", " ", "", "" ,"" ,"", "", "", "", "", "", "", "", "", "", "", "", "", CustomerName, "" ); //Create Method in order to pass information into
entry.close();
}
cAssess = dbBulletHelper.fetchSlideInfobyCateandAssess("Current Product Overview", fCustomerName);
if (cAssess.moveToFirst()){
//Exist
}else{
//Not Exist
DBSlideBullet entry = new DBSlideBullet(ReportReview.this); //call upon database pass in context of this class
entry.open();
entry.CreateEntry("Current Product Overview", "Current Product Overview", "1", " ", "", "" ,"" ,"", "", "", "", "", "", "", "", "", "", "", "", "", CustomerName, "" ); //Create Method in order to pass information into
entry.close();
}
cAssess = dbBulletHelper.fetchSlideInfobyCateandAssess("Major Improvement Areas", fCustomerName);
if (cAssess.moveToFirst()){
//Exist
}else{
//Not Exist
DBSlideBullet entry = new DBSlideBullet(ReportReview.this); //call upon database pass in context of this class
entry.open();
entry.CreateEntry("Major Improvement Areas", "Major Improvement Areas - Review", "1", " ", "", "" ,"" ,"", "", "", "", "", "", "", "", "", "", "", "", "", CustomerName, "" ); //Create Method in order to pass information into
entry.close();
}
cAssess = dbBulletHelper.fetchSlideInfobyCateandAssess("Next Steps", fCustomerName);
if (cAssess.moveToFirst()){
//Exist
}else{
//Not Exist
DBSlideBullet entry = new DBSlideBullet(ReportReview.this); //call upon database pass in context of this class
entry.open();
entry.CreateEntry("Next Steps", "Next Steps", "1", " ", "", "" ,"" ,"", "", "", "", "", "", "", "", "", "", "", "", "", CustomerName, "" ); //Create Method in order to pass information into
entry.close();
}
Bundle gotBasket = getIntent().getExtras();
Storage = gotBasket.getStringArray("Storage");
ProductApp = gotBasket.getStringArray("ProductApp");
StandardProc = gotBasket.getStringArray("StandardProc");
Training = gotBasket.getStringArray("Training");
Contamination = gotBasket.getStringArray("Contamination");
OilCondition = gotBasket.getStringArray("OilCondition");
ReliabilityAssessment = gotBasket.getStringArray("ReliabilityAssessment");
Planning = gotBasket.getStringArray("Planning");
//Get User and Customer Email
upHelper = new UserProfileDBAdaptor(this);
upHelper.open();
Cursor cUP = upHelper.fetchAllUserProfile();
cUP.moveToFirst();
UserEmail = cUP.getString(cUP.getColumnIndexOrThrow("Email")).toString();
upHelper.close();
}
Upvotes: 0
Views: 904
Reputation: 14755
android may throw away the complete application from memory (i.e. if memory is required).
This way the content of your variable CustomerName
might be null and calling the trim() method can lead to nullpionterexception.
CustomerName = ((GlobalVariables) this.getApplication()).getSomeVariable();
CustomerName.trim();
Upvotes: 1