I’m starting a service from my activity and then call finish(). The problem is that other classes that was created in the package are null at the onStart of the service and classes that was created at the onStart are when I’m starting new activities.
How to solve this?
Thanks,
Nahum
Here is sample code:
class Bridge
{
static Bridg BridgeInstence;
public Bridge ()
{
BridgeInstance = this;
}
}
class MainActivity
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
JNIBridge b = new JNIBridge(assetManager);
startService(new Intent(this, MainService.class));
finish();
}
public class MainService extends Service
{
public int onStartCommand(Intent intent, int flags, int startId) {
//Bridge.BridgeInstance is NULL here!!!!
}
If you want to access persistent variables across all activities and services of an application, you can extend the Application class and access it from anywhere you have a context. For example:
Also at this point I believe you have to declare your application in the manifest, like: