I have an application, which does smth… at the begining of main class I do the following:
myCommunicator = new Communicator();
// LOAD DB
dbAdapter = new ToDoDBAdapter(this);
dbAdapter.open();
// CHECK CHANNEL CHANGES
try {
dbHandler = dbAdapter.getAllChannelNames();
startManagingCursor(dbHandler);
String md5Channels = "";
while (dbHandler.moveToNext())
{
String xy = dbHandler.getString(0);
md5Channels += xy;
}
// 2. Make MD5 string
md5Channels = myCommunicator.md5(md5Channels);
// 3. Compare MD5
ChannelsArray = myCommunicator.getChannels(md5Channels);
// 4. Update if needed
if(ChannelsArray.length() > 0)
{
dbAdapter.populateDB(ChannelsArray);
}
dbHandler = dbAdapter. getAllToDoItemsCursor();
}
catch (JSONException e) {
Log.d(" - PopulateChannels - ", "Napaka: " + e.toString());
}
myCommunicator, dbAdapter, dbHandler, ChannelsArray are defined…
Than I have
public Cursor getChannelCursor()
{
return dbHandler;
}
public ToDoDBAdapter getDBAdapter()
{
return dbAdapter;
}
public Communicator getCommunicator()
{
return myCommunicator;
}
public JSONArray getChannelsArray()
{
return ChannelsArray;
}
This class have tabhost * will call it Activity1… And when I call from another class * will call it Activity2…(inside tabost) the result is null …
So when I do Activity1.getChannelsArray(); (or any other function) from Activity2 it is always null… Have no idea how to solve it…
Hi, sorry for lack of infos…
I have main activity… called at the beginning (Activity1)… I populate DB there (if any changes) and create DB Cursor… This activity hold TabHost…
The easiest way to explain is to write some code:
Here is Activity1 (main activity)
package com.Avtivity1;
public class activity1 extends Activity
{
public void onCreate(Bundle savedInstanceState) {
...
dbAdapter = new ToDoDBAdapter();
}
public ToDoDBAdapter getDBAdapter()
{
return dbAdapter;
}
}
And now another one:
package com.Avtivity1;
public class activity1 extends TabActivity implements OnTabChangeListener
{
private ToDoDBAdapter dbAdapter;
@Override
public void onCreate(Bundle icicle) {
...
Activity1 Activity1 = new Activity1();
Activity1.getDBAdapter();
}
public ToDoDBAdapter getDBAdapter()
{
return dbAdapter;
}
}
And this part Activity1.getDBAdapter(); always returns null…
In general, don’t persist data in an
Activitythat needs to be used in other parts of the Application. The life of an Activity cannot be relied on since the system might reclaim it’s resources based on needs such as low memory.Instead, store your values in a singleton non-Activity class.