Monthly Archives: July 2013

Check whether service running

Method found on stackoverflow but it doesn’t appear to be the best answer. After stopping a service, this method may still see it as running. This is presumably because android will clear it our in its own time. The method I … Continue reading

Posted in Android | Leave a comment

Get & set text on view

To get a string/value: EditText e1 = (EditText)findViewById(R.id.count2a); int i = Integer.parseInt(e1.getText().toString()); To set from an activity: ((TextView)findViewById(R.id.score)).setText(Integer.toString(score)); To set from a fragment: ((TextView)view.findViewById(R.id.textView1)).setText(myCurrency1); To use a string from strings.xml: ((Button)findViewById(R.id.button2)).setText(R.string.sched_stop);  

Posted in Android | Leave a comment

Download xml file & write to sd card

1. Download xml file The solution that suited me best was largely built on this stackoverflow entry. I put it in an AsyncTask. Remember manifext update: <uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”></uses-permission> <uses-permission android:name=”android.permission.INTERNET”></uses-permission> <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”></uses-permission> In main activity. URL url = null; try … Continue reading

Posted in Android | Leave a comment

Pass data from fragment to activity

This is my preferred solution from the stackoverflow answers seen (mainly this one from Harlo Holmes). Any fragment that should pass data back to its containing activity should declare an interface to handle and pass the data. Then make sure … Continue reading

Posted in Android | Leave a comment

Pre-load database in app

To provide data in the apk in the form of a database it must be done in 2 stages: create your database and table and copy the file into the app write code in your app to copy that file into … Continue reading

Posted in Android | Leave a comment

Multi-line toast

To put toast message over more than one line:   Toast.makeText(MainActivity.this, “Line1 : ” + string1 + “\n” + “Line 2: ” + string2, Toast.LENGTH_LONG).show();

Posted in Android | Leave a comment

Create new app in Eclipse as copy of another

Several responses found (eg stackoverflow), this method tried and tested. Open project, right click & copy. On main menu, Edit, Paste and give new name when prompted. Edit manifest, change package name(s) to new name(s) in all references in manifest. … Continue reading

Posted in Android | Leave a comment