Android :: Calling GetSharedPreferences(); From SQLiteOpenHelper Class?

Feb 27, 2010

I have two classes, one MainClass and one DataBaseHelper class, which extends SQLiteOpenHelper.

From my MainClass I call a method in the DataBaseHelper class to open a data base. Before opening the data base I want to check the users data base version (this is important as soon as I want to update the data base and push it to the Android market). So from the DataBaseHelper class I call the following method, which is in the MainClass.

CODE:..........

I call the checkCurrentDbVersion() method from the DataBaseHelper class like so:

CODE:.....................

As soon as the debugger runs the following line, it stops.

CODE:...........

I have no constructor defined. Could that be the failure?

Android :: calling getSharedPreferences(); from SQLiteOpenHelper class?


Android :: Android - Use One SQLiteOpenHelper Class For Multiple Database Files

Nov 20, 2010

My app uses two databases (separate files). To handle these databases I have created two Helper classes which extend SQLiteOpenHelper, one for each database.

I am now going to add a third database and wonder whether I need to create yet another Helper class (and if I used a 4th and a 5th database would I need even more Helper classes), or can I use the same Helper class for multiple databases?

The problem that I see with trying to use just one Helper class is that I can't see how to pass the name of the individual database files to the Helper. At present the name of the database is hard-coded as a Static field of each of the Helper classes, but if I had only one Helper class I would need to be able to pass the different names in to the Constructor when creating the separate Helper objects; the problem is that the SQLiteOpenHelper Constructor seems to be called by Android with just one parameter: the Context.

View 2 Replies View Related

Android :: Calling An Id In An Xml File In Your Class

Nov 17, 2010

How can I detect whether or not an Image View has a picture in it upon a button click. I had a class that displays a picture and some results, but I don't want the user to be able to access those results (pushing the button) until the results have been written to that class.

So, I figured I needed to check to see if there was a picture displayed in the ImageView yet.

So something like:

CODE:...............

But obviouslt R.id.photoResultView == null isn't the right way to do it...anyone know how?

EDIT: Line 184

CODE:........

EDIT:

CODE:.......................

View 2 Replies View Related

Android : Droid Calling Intent From Another Class?

Jun 29, 2010

I am calling intents alot in my program and I thought that I could write a public class that would have all of my intents so I can just call something like intents.testIntent(params) and then have it fire off the intent.

I tried it out but am getting a force close with a null pointer exception. This is my whole class. I know it is probably sloppy but I have just been learning java for 2 months so I still am an amateur. Any way, my code...

View 1 Replies View Related

Android :: Calling Function From Receiver Class Not Working

Apr 20, 2010

I have a SMSReceiver class that needs to pass the phone number and message to another class. Which works but when I call that class I need the function to read preference to compare if it needs to execute another function.

View 2 Replies View Related

Android :: How To Stop Service Method Of Calling Activity Class?

Jul 2, 2010

I am trying to call my service class's stopService() method from my activity. But I don't know how to access stopservice method from my activity class. I have the below code but its not working. This is HomeScreen class:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
enablecheck = (CheckBox)findViewById(R.id.enablecheck);
enablecheck.setOnCheckedChangeListener(new OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(enablecheck.isChecked()){
startService(new Intent(HomeScreen.this, AutoService.class));
} else {
stopService(new Intent(HomeScreen.this, AutoService.class));
} } });
}
This is Service Class:
public class AutoService extends Service {
private static final String TAG = "AutoService";
private Timer timer;
private TimerTask task;
@Override
public IBinder onBind(Intent intent) {
return null;
} @Override
public void onCreate() {
Toast.makeText(this, "Auto Service Created", Toast.LENGTH_LONG).show();
Log.d(TAG, "onCreate");
int delay = 5000; // delay for 5 sec.
int period = 5000; // repeat every sec.
timer = new Timer();
timer.scheduleAtFixedRate(task = new TimerTask(){
public void run() {
System.out.println("done");
} }, delay, period);
}
@Override
public boolean stopService(Intent name) {
// TODO Auto-generated method stub
timer.cancel();
task.cancel();
return super.stopService(name);
} }

View 3 Replies View Related

Calling Class - Getting Error And Program Stop Working?

Oct 12, 2011

am trying to call a class from the main and am getting an error and the program is stop working. am trying to call from the main.class the test.class

on the main i have write the following code

Intent connectIntent2 = new Intent(Conn.this, Test.class);
startActivity(connectIntent2);

and on the test.java i have write[code]....

the R.id.button_scan is been define in the main.xml and i just want to make it invisible.

View 1 Replies View Related

Android :: How To GetSharedPreferences In Dialog

Feb 15, 2010

I want to read file in dialog

can any one guide me how to achieve this?

when i use code...

View 1 Replies View Related

Android :: Method GetSharedPreferences - String - Int - Is Undefined?

Sep 24, 2010

I have the following code but there is an error: "The method getSharedPreferences(String, int) is undefined for the type EventsData".

Does it mean I need to extend both SQLLiteOpenHelper and Activity?
CODE:.............

View 2 Replies View Related

Android :: SQLiteOpenHelper Per Activity?

Jul 21, 2010

Do I need an instance of my SQLiteOpenHelper class for each Activity I have? I have 1 currently that all activities access, but started getting an exception

"illegal state exception SQLiteDatabase created and never closed "

on simple a simple query and I can't seem to figure out why this is happening. I read online about this, and wanted to try to understand why the SQLiteOpenHelper was dependent on an Activity.

Is there a way to just have open SQLiteDatabase object without the Helper and have it just exist within all activities?

View 10 Replies View Related

Android :: SQLiteOpenHelper - OnUpgrade

Sep 10, 2009

I get a SQLiteException if I try to issue an alter statement in the onUpgrade method of SQLiteOpenHelper subclass:

Can't upgrade read-only database from version X to Y: /path/to/db

That makes no sense at all! Where did I go wrong?

View 5 Replies View Related

Android :: Having Several SQLiteOpenhelper In One Appli?

Feb 11, 2010

I would like to know if it is possible to have several DbOpenHelper in the same app Android but to use them to write and read in the same database? because I'm trying to create tables from 2 different OpenHelper (with different names) and only the first one seems to create. when I try to run the 2nd one, i get an error...

View 1 Replies View Related

Android :: SQLite Using The SQLiteOpenHelper

Jun 9, 2010

I have a SQLite database, and several tables within that datbase. I am developing a DBAdapter for each table within the database. (reference Reto Meier's Professional Android 2 Application Development, Listing 7.1).

I am using the adb shell to interface with the database from the command line and see that the database is being populated as I expect. Occasionally, I want to drop a table so that I can ensure it's being built properly, from scratch.

The problem is that SQLiteOpenHelper only checks to see if the database exists. Is there a typical solution to writing a helper to also see that the table(s) exists? Basically once I drop a table, the helper checks to see that the database exists and assumes all is well.

Also, the CREATE_DATABASE string used in the reference above only creates the one table. Should I consider using the DBAdapter for an adapter to ALL of my tables? That doesn't seem as clean to me.

View 1 Replies View Related

Android :: SQLiteOpenHelper OnUpgrade()

Aug 17, 2010

I am doing my first app with a database and I am having a little trouble understanding the onUpgrade function. My database has a table with an items and a favorite column so that the user can favorite an item. Most implementations I see simply drop the table and reconstruct it but I don't want to do this. I want to be able to add more items to the table.

When the app is upgraded through the android marketplace does the database know its version number? So could I increment the version number in the code and then export it to the marketplace and when the user boots up the upgraded version for the first time then onUpgrade will be called?

If this is the case my onUpgrade would simply pull from a file and add the database items in. Is this a standard way of doing things or is there a better way of handling this in Android. I am trying to stay as standard as possible.

View 1 Replies View Related

Android :: SQLiteOpenHelper Documentation Not Clear

Jul 9, 2010

The documentation does not make the interation between onUpgrade() and onCreate() clear.

When implementing onCreate() should this create the database at version 1, assuming that onUpgrade will apply all of the patches to bring it up to version x (lets say version 5 for example)? Or should onCreate build the latest version of the database, and onUpgrade is only used to upgrade legacy clients.

I kind of prefer the first, because it effectively means that the same SQL is executed for everybody. Whereas the second options means that there is a potential for onCreate to build something slightly different to the succession of patches built by onUpgrade.

I can always make onCreate call into onUpgrade, however, this is the kind of implementation detail that should go into the javadocs...

View 3 Replies View Related

Android :: SQLiteOpenHelper Without Or Less Restrictive Use Of Context?

May 21, 2010

If you extend SQLiteOpenHelper, for the Constructor you have to use a Context. I am wondering if there is a way to leave this out, and be able to work with database tables without a Context.

Or at least be least restrictive, I mean a way of project/class structure that will make history the several context passings I have to do now.

As it is my application has several level of classes, chained in each other, and there are a few that connects to the database, but have no whatsoever influence on the interface, so they don't actually need the Context.

Are you creating your classes in the way that you pass each time a Context to them?
If not, how you do, how you reuse a Context in a short class?

View 1 Replies View Related

Android :: Why Isn't SQLiteOpenHelper Called Just SQLiteHelper

Jun 11, 2010

The documentation describes the class as a helper object to create, open, and/or manage a database. Having that in mind wouldn't you say that the name is a little misleading?

View 2 Replies View Related

Android :: Why SQLiteOpenHelper.onUpgrade Fail?

Sep 13, 2010

Every time i increase my database version and push the upgraded app to the users, something weird happens.. For some it works perfectly fine, and some report crashes (including through the Market's reporting system) caused by the lack of table columns i just added in onUpgrade.

If you want to see the method:
http://code.google.com/p/tag-todo-list/source/browse/trunk/Donut/src/com/android/todo/data/ToDoDB.java#136

I can't spot any exceptions that appear in onUpgrade. What i'm currently doing to bypass these problems is intercepting the exceptions where the new fields are invoked for the first time and then calling onUpgrade 'manually', which is kind of dirty.

Also, the app sometimes generates a 'no such table' SQLiteException when accessing the main table (again, only for some users) which is incredibly strange... Does someone know why these things happen? Or can you spot something wrong in my code?

View 1 Replies View Related

Android :: SQLiteOpenHelper Existing Database?

Jun 9, 2010

I have an existing SQLite database file from another project.

Where do I include the database file into my Eclipse project to have it deploy with the app.

Do I need to indicate that the database file is writable? (In the iPhone world you need to copy the database file from the app's bundle to a writable folder on the iPhone proper before first use.)

Once I have the database file on the phone, how do I tell SQLiteOpenHelper to use it? (I extend SQLiteOpenHelper in a custom class.

View 1 Replies View Related

Android :: How To Emulate OnUpgrade Call In SQLiteOpenHelper

Oct 17, 2010

How can I emulate an onUpgrade call for my SQLiteOpenHelper class? I have tried changing the version number in my SQLiteOpenHelper class and versionCode in manifest but onUpgrade is not called. Any idea? I need to check my onUpgrade code before upload it to the market, I don't want my app's users get a buggy upgrade.

View 10 Replies View Related

Android :: Database In Application - SQLiteOpenHelper GetType?

Aug 24, 2010

I'm trying to implement a database in my application. I'm following a tutorial about writing my own ContentProvider, but I'm confused about SQLiteOpenHelper::getType. We're supposed to write it and, essentially, write a switch that returns the MIME type corresponding to the type of data we're dealing with.

I don't fully understand it. I'm not sure, even though I have an example, what is precisely supposed to be conveyed here. How do I determine the MIME type of my different tables of data?

View 1 Replies View Related

Android :: SQLiteOpenHelper.getWriteableDatabase() Null Pointer Exception

Nov 16, 2009

I've had fine luck using SQLite with straight, direct SQL in Android, but this is the first time I'm wrapping a DB in a ContentProvider. I keep getting a null pointer exception when calling getWritableDatabase() or getReadableDatabase().

Is this just a stupid mistake I've made with initializations in my code or is there a bigger issue?

CODE:.........

But here's LogCat showing the exception:

View 2 Replies View Related

Android :: Creating A New Class Using Eclipse New Java Class Dialog Box

Jul 7, 2010

I'm creating a new class, using eclipse "New Java Class" dialog box. I can write the superclass I want (I can't find using "browse" button), but I can't write or select an interface to implement. I click "add" but ther is nothing to select. What I'm doing wrong?

View 4 Replies View Related

Android :: Communicating Between Receiver Class And An Activity Class

Jul 14, 2010

I'm just getting into Android development, and I have a question about communicating between a receiver class and an activity class. I'm very new to JAVA and Android so I hope I don't sound too stupid. I'm developing an application where I intercept an SMS message and then based on various elements of that SMS I might delete it once it's been saved to the inbox. I have a receiver class that intercepts the txt message, and I am also able to delete messages from my inbox with code in the activity class using a button at the moment. The problem I have is communicating between the receiver class and the activity class where the code to delete a message resides. I tried putting that code directly into the receiver class but as I'm sure most of you already know the BroadcastReceiver class doesn't seem to support what I need to delete messages. I've been searching for an answer to this for a while, but haven't been able to find anything. Honestly I'm not sure I know enough about JAVA and Android to even recognize a solution if I saw it.

View 2 Replies View Related

Android :: Accessing Class Level Stuff From Inner Class

Jun 27, 2010

What I want to do, is be able to access the object neoApi inside the Neoseeker class, from its inner class RunningTimer. Now, in my code, you can see what I would think to work, but when I run my application, nothing pops up. Nothing inside my TextView, no Toast, nothing at all. How can I remedy this?

package com.neoseeker.android.app;
import java.util.Timer;
import java.util.TimerTask;
import org.json.JSONObject;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;.......................

View 1 Replies View Related

Android :: Access Application Class From Class Other Then Activity

Sep 8, 2010

I'm new to Java and android development. In my application I need data which is accessible for a few activities. I've read that a good solution is to use Application class for this. So I use it like this:

public class MyApplication extends Application {
private String str;
public String getStr(){
return str;
}
public void setStr(String s){
str = s;
}
}

and I can access this variable from activity like this:........................................

View 2 Replies View Related

Android :: Call Activity Class From Other Java Class?

Oct 8, 2010

I have just started android. I just want to know that how can i call activity class from other java class. i just want to pass class object to activity class.

public class GsonParser extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MagazineThread thread=new MagazineThread();
thread.start();
}
public GsonParser(JsonMagazineParser Obj)
{

}
}

and i am just doing like from other class. GsonParser obj=new GsonParser(this);passing obj to activity class.how can i achieve that.

View 1 Replies View Related

Android :: How To Run Class In Background Among Package Of Class?

Apr 23, 2010

In my app in one package there are some classes. from those classes i want to run one class that is the Gps functionality class. i want to run that class in background. how i do it, i don't know. i am not able to make it solve from any document. if anybody knows the way to solve it please me by run a "hello world" app in the background. i am not able to solve this problem by going through document.

View 2 Replies View Related

Android :: In Java, What Does A Reference To Class.class Do?

Jul 20, 2010

I'm building a small Android application, but this is more of a Java question than an android question. Looking through the tutorials there are lines that look like: startService(new Intent(this, MyService.class));

What exactly does the "MyService.class" field represent? Is that just a reference to the class for a template?

View 4 Replies View Related

Android :: Dialog Class With It's View Class?

May 19, 2009

I made a Dialog Class with it's view classI want to pop up the dialog when I got some packets from network. so I made a Thread which parses packets and then I made if clause in Run() method There is no problem with parsing packet but when I enter "if clause" and call showDialog() I got Error message

Is there anyone who knows how to pop up a dialog from different thread?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved