Hi Friend's recently i have created android application for election management(Voter search and other statics and reports as well as Messaging voter details).
I have developed this application for one of my client , Application requirement was storing almost 3 To 4 Lakh Record's in local phone memory without using internet and this was biggest challenge for bcz I have not studied android and this was my first app in android .
I'm Posting some codes which may help you ............
MainActivity.java
This is my main activity code which create Database and do AsynTask like showing progress bar.........
package com.example.rajmal.dummy;
import java.io.IOException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.database.sqlite.SQLiteDatabase;
@SuppressLint({ "ParserError", "ParserError" })
public class mainactivity extends Activity implements OnClickListener {
protected Button btnmarathi;
protected Button btnenglish;
protected Button btnSendMessage;
Context context;
private int mProgressStatus = 0;
private ProgressDialog mProgressDialog ;
private ProgressBarAsync mProgressbarAsync;
protected SQLiteDatabase db,db1,db2,db3,db4,db5,db6;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmarathi);
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mProgressDialog = new ProgressDialog(this);
/** Close the dialog window on pressing back button */
mProgressDialog.setCancelable(false);
/** Setting a horizontal style progress bar */
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
/** Setting a message for this progress dialog
* Use the method setTitle(), for setting a title
* for the dialog window
* */
mProgressDialog.setMessage("Initializing Database .....");
mProgressDialog.show();
/** Creating an instance of ProgressBarAsync */
mProgressbarAsync = new ProgressBarAsync();
/** ProgressBar starts its execution */
mProgressbarAsync.execute();
btnmarathi = (Button) findViewById(R.id.btnmarathi);
btnenglish = (Button) findViewById(R.id.btnEnglish);
btnSendMessage=(Button)findViewById(R.id.btnsendmsg);
}
public void CreateDb()
{
db = (new DatabaseHelper(this)).getWritableDatabase();
db1 = (new DatabaseHelper1(this)).getWritableDatabase();
db2 = (new DatabaseHelper2(this)).getWritableDatabase();
db3 = (new DatabaseHelper3(this)).getWritableDatabase();
db4 = (new DatabaseHelper4(this)).getWritableDatabase();
db5 = (new DatabaseHelper5(this)).getWritableDatabase();
db6 = (new DatabaseHelper6(this)).getWritableDatabase();
}
public void handleClick(View v){
//Create an intent to start the new activity.
// Our intention is to start secondActivity
switch(v.getId())
{
case R.id.btnmarathi:
Intent intent = new Intent();
intent.setClass(this,Menuclick.class);
// db2 = (new DatabaseHelper2(this)).getWritableDatabase();
startActivity(intent);
break;
case R.id.btnEnglish:
Intent intent1 = new Intent();
intent1.setClass(this,Menuclick.class);
// db3 = (new DatabaseHelper3(this)).getWritableDatabase();
startActivity(intent1);
break;
case R.id.btnsendmsg:
Intent intent2 = new Intent();
intent2.setClass(this,SendSMSActivity.class);
startActivity(intent2);
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.layout.mainmarathi, menu);
return true;
}
@Override
public void onClick(View v) {
// Intent myintent = new Intent(mainactivity.this, EmployeeList.class);
// startActivity(myintent);
}
private class ProgressBarAsync extends AsyncTask<Void, Integer, Void>{
/** This callback method is invoked, before starting the background process */
@Override
protected void onPreExecute() {
super.onPreExecute();
// mProgressStatus = 0;
}
/** This callback method is invoked on calling execute() method
* on an instance of this class */
@Override
protected Void doInBackground(Void...params) {
CreateDb();
return null;
//return null;
}
/** This callback method is invoked when publishProgress()
* method is called */
/* protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
mProgressDialog.setProgress(mProgressStatus);
}*/
/** This callback method is invoked when the background function
* doInBackground() is executed completely */
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
mProgressDialog.dismiss();
}
}
}
I have developed this application for one of my client , Application requirement was storing almost 3 To 4 Lakh Record's in local phone memory without using internet and this was biggest challenge for bcz I have not studied android and this was my first app in android .
I'm Posting some codes which may help you ............
MainActivity.java
This is my main activity code which create Database and do AsynTask like showing progress bar.........
package com.example.rajmal.dummy;
import java.io.IOException;
import android.os.AsyncTask;
import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;
import android.database.sqlite.SQLiteDatabase;
@SuppressLint({ "ParserError", "ParserError" })
public class mainactivity extends Activity implements OnClickListener {
protected Button btnmarathi;
protected Button btnenglish;
protected Button btnSendMessage;
Context context;
private int mProgressStatus = 0;
private ProgressDialog mProgressDialog ;
private ProgressBarAsync mProgressbarAsync;
protected SQLiteDatabase db,db1,db2,db3,db4,db5,db6;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmarathi);
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mProgressDialog = new ProgressDialog(this);
/** Close the dialog window on pressing back button */
mProgressDialog.setCancelable(false);
/** Setting a horizontal style progress bar */
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
/** Setting a message for this progress dialog
* Use the method setTitle(), for setting a title
* for the dialog window
* */
mProgressDialog.setMessage("Initializing Database .....");
mProgressDialog.show();
/** Creating an instance of ProgressBarAsync */
mProgressbarAsync = new ProgressBarAsync();
/** ProgressBar starts its execution */
mProgressbarAsync.execute();
btnmarathi = (Button) findViewById(R.id.btnmarathi);
btnenglish = (Button) findViewById(R.id.btnEnglish);
btnSendMessage=(Button)findViewById(R.id.btnsendmsg);
}
public void CreateDb()
{
db = (new DatabaseHelper(this)).getWritableDatabase();
db1 = (new DatabaseHelper1(this)).getWritableDatabase();
db2 = (new DatabaseHelper2(this)).getWritableDatabase();
db3 = (new DatabaseHelper3(this)).getWritableDatabase();
db4 = (new DatabaseHelper4(this)).getWritableDatabase();
db5 = (new DatabaseHelper5(this)).getWritableDatabase();
db6 = (new DatabaseHelper6(this)).getWritableDatabase();
}
public void handleClick(View v){
//Create an intent to start the new activity.
// Our intention is to start secondActivity
switch(v.getId())
{
case R.id.btnmarathi:
Intent intent = new Intent();
intent.setClass(this,Menuclick.class);
// db2 = (new DatabaseHelper2(this)).getWritableDatabase();
startActivity(intent);
break;
case R.id.btnEnglish:
Intent intent1 = new Intent();
intent1.setClass(this,Menuclick.class);
// db3 = (new DatabaseHelper3(this)).getWritableDatabase();
startActivity(intent1);
break;
case R.id.btnsendmsg:
Intent intent2 = new Intent();
intent2.setClass(this,SendSMSActivity.class);
startActivity(intent2);
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.layout.mainmarathi, menu);
return true;
}
@Override
public void onClick(View v) {
// Intent myintent = new Intent(mainactivity.this, EmployeeList.class);
// startActivity(myintent);
}
private class ProgressBarAsync extends AsyncTask<Void, Integer, Void>{
/** This callback method is invoked, before starting the background process */
@Override
protected void onPreExecute() {
super.onPreExecute();
// mProgressStatus = 0;
}
/** This callback method is invoked on calling execute() method
* on an instance of this class */
@Override
protected Void doInBackground(Void...params) {
CreateDb();
return null;
//return null;
}
/** This callback method is invoked when publishProgress()
* method is called */
/* protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
mProgressDialog.setProgress(mProgressStatus);
}*/
/** This callback method is invoked when the background function
* doInBackground() is executed completely */
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
mProgressDialog.dismiss();
}
}
}
Comments
Post a Comment