Adit >
Developer Pages >
Porting to Android
Porting To Android
Net2Droid - A Tool for Developers
Faced with the prospect of porting a dozen or so programs from Windows Mobile
(vb.net 2005/2008) to Google Android, we decided to build a Visual Studio Add-in
to do the donkey work.
Net2Droid ports vb.net compact framework programs to the Android platform
It has worked well for us, and could do the same for you?
For Developers coming from a VB background
Once you have your Hello Android app up and running, you will no doubt want to progress
to more exciting things, and here are a few pointers that may help
Case Sensitive
Everything is CASE SENSITIVE, Comments are //
Displaying a message or alert
Write a function that simply wraps construction of 'toast' - and call it
something that is meaningful to you, for example:
private void ShowAlert(String message){
Context context = getApplicationContext();
CharSequence text = message;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
or maybe:
private void MessageBox(String message){
Context context = getApplicationContext();
CharSequence text = message;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
Showing another form
private OnClickListener PayButtonListener = new OnClickListener()
{
public void onClick(View v)
{
Intent i = new Intent(main.this, newtalk.class);
startActivity(i);
}
};
(main is the name of the form we are on, newtalk is the name of the form we are calling)
Passing data to another form
On the calling form
Intent i = new Intent(weekform.this, dayform.class);
b1 = new Bundle();
b1.putLong("Employee", Eindex);
b1.putString("EmpName", EmpName);
i.putExtras(b1);
startActivityForResult(i,1);
On the receiving form
b = new Bundle();
b = this.getIntent().getExtras();
if (b.isEmpty())
{
}else
{
Eindex = b.getLong("Employee");
EmpName = b.getString("EmpName");
}
Displaying an hourglass or wait cursor
private OnClickListener B1Listener = new OnClickListener()
{
public void onClick(View v)
{
MyDialog = ProgressDialog.show(pubform.this,"Your Message","Please wait ...", true,true);
MyDialog.show();
try
{
Handler ahandler = new Handler();
ahandler.postDelayed(new Runnable() {
public void run() {
//---------------------
//Your processing here
//---------------------
MyDialog.dismiss();
}
}, 100);
}catch (Exception e){
//ShowAlert(e.getMessage());
}
}
};
Simple file handling
private Integer ReadId(){
private void WriteId(Integer IdToWrite){
String FileName = "example.dat";
try
{
OutputStreamWriter out = new OutputStreamWriter(openFileOutput(FileName,0));
out.write(IdToWrite.toString());
out.close();
}catch (Exception e){
}
}
String FileName = "example.dat";
Integer LocalId = 0;
try {
InputStream instream = openFileInput(FileName);
InputStreamReader inputreader = new InputStreamReader(instream);
BufferedReader buffreader = new BufferedReader(inputreader);
String line = buffreader.readLine();
LocalId = Integer.parseInt(line);
instream.close();
} catch (Exception e) {
}
return LocalId;
}
Consuming a web service