Tag: java

Clearing preferences in SharedPreferences in Android, not just Values

from what I can incur out of the SharedPreferences documentation, I can update a preference, add one or clear all preference values in a shared preference file. But I want to completely clear everything inside a shared preference file, not just the values, but the preferences they refer to as well.

How one interface can be used for different background android tasks?

Well, I have an activity class with two background task (Async-Task) which have been defined in two separate classes like public class GettingBeaconsList extends AsyncTask<String, String, String> public class GettingAirports extends AsyncTask<String, String, String> which are initialized and executed in MainClass public class MainClass extends Activity implements DelegateTaskCompleted { int ServiceBoolean = 0; public OnClickListener […]

Encryption of video files?

I am using this method for encrypting a video file: public static void encryptToBinaryFile(String password, byte[] bytes, File file) throws EncrypterException { try { final byte[] rawKey = getRawKey(password.getBytes()); final FileOutputStream ostream = new FileOutputStream(file, false); ostream.write(encrypt(rawKey, bytes)); ostream.flush(); ostream.close(); } catch (IOException e) { throw new EncrypterException(e); } } private static byte[] encrypt(byte[] raw, […]

Not able to dynamically set the setVisibility() parameter

I am trying to set the visibility for a button as follows: public Bundle setActivityState(Bundle bundle){ startBtn = (Button) findViewById(R.id.startSensorsBtn); startBtn.setVisibility( getVisibilityState(bundle, PersistanceConstants.START_BTN_STATE) ); return bundle; } public int getVisibilityState(Bundle bundle, String keyName){ if (bundle.getInt(keyName) == View.VISIBLE){ return View.VISIBLE; } else if (bundle.getInt(keyName) == View.INVISIBLE){ return View.INVISIBLE; } else if (bundle.getInt(keyName) == View.GONE){ return View.GONE; […]

How to use writeStringArray() and readStringArray() in a Parcel

I recently came across a very stupid (at least from my point of view) implementation inside Androids Parcel class. Suppose I have a simple class like this class Foo implements Parcelable{ private String[] bars; //other members public in describeContents(){ return 0; } public void writeToParcel(Parcel dest, int flags){ dest.writeStringArray(bars); //parcel others } private Foo(Parcel source){ […]

Swiping to the next Fragment with a button click

Please have a look at the following code. FirstView.java import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; public class FirstView extends Fragment { private TextView firstText; private Button btn; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_view1,container,false); firstText = (TextView)view.findViewById(R.id.viewOneText); […]

“.android” folder and “debug.keystore” file missing

am using Linux opensuse, eclipse helios package i have to import google maps in my application for which i need an API key, so in order to get the api key i need to get the MD5 sum value which has to be got by running the debug.keystore file using keytool but the problem is […]

How to create a global variable in android?

This question already has an answer here: Android global variable 12 answers

Android Bind Service returns false every time

boolean isBound = bindService(new Intent(SocketServiceController.this, SocketService.class), mConnection, Context.BIND_AUTO_CREATE); Bind service always returns false for me… Could anyone tell me the possible errors that i could have made… Service code is as follows public class SocketService extends Service{ @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return myBinder; } private final IBinder myBinder […]

How access existing sqlite database on Android Emulator?

So im new to working with databases in android, and I cant seem to figure out how to view a created database. I created the database adapter class and in my main activity class. I run it in the emulator with no issues, but how do I view the contents? The book im reading says […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.