How
I developed my Android App on Eclipse using PHP-MySQL database (running wamp
server)
My
working Environment :
Front End : ECLIPSE
Back End : PHP-MySQL
Server used : Wamp Server
App
Development Modules :
· Creating
Activity Layouts
· Adding
widgets and other interfacing elements(textboxes, edit texts and whatever )
· Creating
button onclick events
· Connecting
these layouts(or simply pages :p) using intents
·
Database
connectivity
ü Working
with wamp
ü The
php-mysql side
Errors
that I fought with in each module :
Creating
Activity Layouts:
Ø Right
click on your project
Ø Click
on new
Ø Click
on other
Ø Then
Android activityàBlank Activityà
Give a name to your activity starting with a capital letteràclick
finish and you are done!!
Problem 1 :
While using downloaded
layouts from external sources in our project, we usually come across the weird
“unfortunately the app has stopped ”
stuff and the subsequent app crash.
Solution :
A
general solution to this problem is adding an activity tag for the downloaded
layouts in our android manifest file.
Example :
<activity
android:name="packagename.Addemp" />
Here “Addemp”
is the java class name for the layout and “packagename” is the name of the package listed under the “src”
folder in your app. Just add this inside your
<application></application > tag
Problem 2 :
While
creating the layout xml file and the java file separatelyfor creating an
activity rather than creating a new activity (which creates both the java and
xml file and connects it), we will
have to manually configure the java file to
connect both.
Solution :
this
can be solved by adding the name of the layout xml file correctly in the setContentView of java file
Example :
The
layout file addemployee.xml file can
be connected to the java file by updating the setContentView of java file as setContentView(R.layout.addemployee);
Problem 3 :
While
working with projects that is associated with internet, contact access, gps,
wifi state, write to SD card etc, we might get permission errors.
Solution :
These
errors can be avoided by adding a permission setting in android manifest file.
Example :
The
permission setting for internet access is
<uses-permission android:name="android.permission.INTERNET"
>
</uses-permission>
Creating
buttons and setting setOnClickListener
Ø Once
you have created your android activity as mentioned before, drag and drop a
button into your layout xml file
Ø Double
click on your button and note down(jst keep in mind :p) your button id.
Ø Now
go to your java file associated with this android activity and declare a new
button(let it be Button b1; )
Ø Now
attach this button b1 to the button id earlier created in the layout file like
this
b1=(Button)findViewById(R.id.button1);
Assuming
the button id as button1.
Ø Now
to make the button to perform some task when clicked, type
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated
method stub
}
});
Don’t copy paste the
code as it may treat you with a bunch of errors!! So just type it, and the auto
complete feature will help you
Ø Anything
you would like the button to perform can be specified within the
method as,
onClick(View
arg0)
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated
method stub
startActivity (new Intent (MainActivity.this, Addemp.class));
}
});
This method
is used to move from one android activity to another on a button click. Usage
of “intent” to move from one activity to another is described in the coming
sections.
Problem 1 :
The
OnClickListener inside the setOnClickListener is highlighted
in red.
Solution :
clicking the error button it says import OnClickListener, tap that to
perform the import and if that too don’t work remove the
import and tap ctrl+shift+O and hopefully this should fix it.
Handling “Intents”
As
mentioned before intents can be created as
startActivity
(new Intent (MainActivity.this,
Addemp.class));
where MainActivity
is the current class(java file of current android activity) and
Addemp.class is the java class of android activity which should be displayed on
button click.
Database Implementation
Back
End : PHP-MySQL Server used : Wamp Server
In order to start implementing database connectivity
in your project, assuming you are beginners, it is always recommended(I recommend!!
:p) to start developing on an already implemented project available for
download on the internet. If you get the android source files, php files and
mysql table details, it is always easy to get started and finally editing down
the contents to suit your project. By going this way you can get an absolute knowledge
about the project implementation. Trust me, I too have learned this way.
By the way I have developed a project by editing
one I downloaded from somewhere, which
is available for download below. You may download the project and edit
yourselves to build your project.
In order to successfully run your project, follow
the steps below :
Ø Download
and install wamp server
Ø Open
wamp server by typing localhost in the default web browser and import the downloaded
database.
Ø Now
close wamp(ensure it runs in background by seeing the wamp icon on taskbar.
Ø Now
go to C:\wamp\www and paste the downloaded php files
Ø Now
open up eclipse and import the android files(import option can be found in fileàimport)
Ø Now
run your android project in eclipse and you are done
Please dont hesitate to ask your doubts regarding app development
You can shoot your doubts by commenting below, one of our admins will get on to help youu...:)
Comments
Post a Comment