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);
} }

Android :: How to Stop service method of calling Activity Class?


Android :: Calling Method From Service Immediately

Sep 3, 2010

I'm pretty sure that android services are going to be the end of me.I have almost no hair left after the last few days.At first I was having a heck of a time getting the service to bind on an onclick of a button, got that straightened out from help here yesterday. Now I actually want the service to bind in the onCreate() method of the activity. That part is no problem, works as intended.My service is actually a socket service to connect TCP sockets to a socket server that I wrote.If I put the call to the method from the bound service mBoundService.StartSocketServer() inside a button click, bingo, works great. But I need this to fire up immediately when the activity loads, so directly under my bindService() call within my onCreate() method of the activity.When I place the call to start the socket inside my onCreate() I get a force-close.

This method (StartSocketServer()) spawns a new thread then opens the socket on that thread to my remote machine.I'm guessing that the problem lies with the new thread generation before the activity fully loads not sure.LogCat is fairly cryptic here. It does say something about thread attach failed, then shows an uncaught handler exception that has "Caused by: java.lang.NullPointerException" within it.Again, if I put this call to the method inside a button click, I"m in business, if it's in the onCreate() it fails. Is there some way inside an activity (presuming that my assumption is correct that it needs to fully load before spawning a new thread) to call the StartSocketServer() after it's loaded: ala body.onLoad() in html?

View 1 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 Get Method Of Listactivity From Activity Class?

Apr 19, 2009

Can i call method of Listactivity from Activity class? I have creates Intent object of myListActivity class and called startIntent() from myActivity class.

View 3 Replies View Related

Android :: Custom Toast - Service Class Does Not Inherit The > FindViewById() Method

May 19, 2010

The problem seems to be that the Service class does not inherit the > findViewById() method.

View 3 Replies View Related

Android :: Inside Service Class / Executing Method For Toast From Scheduled TimerTask

Apr 30, 2010

I am trying to execute a {public void} method in Service, from scheduled TimerTask which is periodically executing.This TimerTask periodically checks a condition. If it's true, it calls method via {className}.{methodName};However, as Java requires, the method needs to be {pubic static} method, if I want to use {className} with {.dot}.The problem is this method is for notification using Toast(Android pop-up notification) and Status Bar.But for this to work, the method must not have {static} modifier and resides in Service class.So, basically, I want background Service to evaluate condition from scheduled TimerTask, and execute a method in Service class.Can anyone help me what's the right way to use Service, invoking a method when certain condition is satisfied while looping evaluation?

View 1 Replies View Related

Android :: Created A Method In Another Class But I Can't Use It In OnClick Method From Main Class

Nov 1, 2010

I created a method called insertTable in a class called Table but i can't use it in my onClick method in the main class :

CODE:.......

I want to do a income.insertTable in the onClick method but eclipse say that i need to create a local variable.

View 3 Replies View Related

Android :: Calling Activity From Service

Nov 19, 2010

i am writing an app in which i need a background service to call an activity and show some result.

View 4 Replies View Related

Android :: Call Method In Main Activity From Custom View Class

Aug 8, 2010

I am using the following method in a new application I'm developing. There is a main activity, which instantiates different classes that extends RelativeLayout and I'm using setContentView to switch between the different modules of the application. I wonder if this is a good approach or necessarily I have to use different activities to the several screens the app haves.

View 1 Replies View Related

Android :: Where To Stop / Destroy Threads In Droid Service Class?

Mar 25, 2009

I have created a threaded service the following way. code...

After I close the application the phone works really slow and I guess it is due to thread termination failure.

Does anyone know what is the best way to terminate all threads before terminating the application?

View 3 Replies View Related

Android : Using Method From A Service In An Activity?

Feb 16, 2010

I have the folowing method in a Service in my appplication: Code... Do I have to do an AIDL or is there a simpler way?

View 2 Replies View Related

Android :: Can Service Report Back To Calling Activity With Status

Jun 29, 2010

Is there a way that a Service can report back to the calling activity when the Service has reached a particular stage of processing? Consider a music player activity that initiates the actual music playing in the background as an Android Service. I want to detect and inform the Activity when the Service has reached the Mediaplayer's onPrepared. Is there a way that the Service can tell the calling Activity when the MediaPlayer's onPrepared is called, to let the Activity know that the audio is prepared and ready to play?I am basically looking to see if there is work around, rather than having a thread in the activity, pinging constantly to check if the Service has reached onPrepared.

View 2 Replies View Related

Android :: Different UI Behavoir Between Activity And Input Method Service

May 20, 2009

I came to this issue : I created a layout with only 1 ImageButton and it works as expected when loaded from Activity (using setContentView) : The button is changing background on touch down event (orange) But not changing when the same layout is loaded by the InputMethodService (but it react to onClickEvent if used ) Here is a minimal project and video if you need to reproduce : http://rzr.online.fr/tmp/rzr-test-android-imf-0.0.20090520.tar.gz

View 4 Replies View Related

Android :: Method Of Service Does Not Take Place Immediately From Inside Activity

Aug 6, 2010

I have an activity A which uses SharedPreferences to share data with a service S, which is called from within A.Now when I call the stopService() method from A, the onDestroy() method in S is not called immediately.I thought that all the activities and services under a single apk run in just one process. Why then does the jump to onDestroy() not take place immediately instead I can see the output from onDestroy() after the further code in the activity A is executed.

View 5 Replies View Related

Android :: Accessing Inner Variable From Outer Class Method In Android Activity

Aug 31, 2010

I m doing some task with following code,
I want to access inner class variable from outer class method.
class Outer extends Activity
{private Handler mHandler = new Handler();
StopTheThread()
{mHandler.removeCallbacks(mUpdateTimeTask);//
This is the what I want to do:
} class Inner
{ final Runnable mUpdateTask = new = new Runnable() {
public void run() {
//Some Code Goes Here
} };
InnerClassMethod()
{ mHandler.removeCallbacks(mUpdateTimeTask);//
This statement working fine here. Here mUpdateTask is inner class variable which is not accessible from outer class.

View 2 Replies View Related

Android :: How Local Service Can Invoke A Sync Method On It's Main Activity?

May 2, 2010

I've configured local service under some app i wanna know how could i invoke methods on the activity, through the service in a synchronous way for example the service invoke a method inthe activity and waiting for for result(synchronous) from it.

View 2 Replies View Related

Android :: Activity Still Lagging When Run Stuff In Service And Handler.post Method / Do This Correctly?

Nov 18, 2010

I'm confused why is my activity still lagging, I use remote service that has few methods and each has its own work like download stuff, process data, compare stuff, etc... It will run in background and update data at selected intervals and notify user of changes over notify system.

The reason why remote service, because I will eventually add a widget, and service needs to stay running even if android kills the activity, so I unbind it on each onPause().
But as far I understand that part doesn't cause my issue.

But back to my problem... so my is Activity still lagging when I run stuff in service and handler.post method.

here is the code...

Also I wanted to add progressDialog to be updated in updateLayer(...) through Activity is a listener to this service, but thats not working well. Whats the best way to update progressDialog? Ever listener, handler, intent, or what?

So how do I do this correctly?

View 2 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 :: 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 :: 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 :: 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?

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 A Non-static Java Method From C

Dec 22, 2009

In my Android app, I need to call a non static java method from C/C++. But i get a blunt crash when i do it using GetMethodID/CallVoidMethod()1 methods.

I have done like this:

1. Register the method using GetMethodID() as follows (mine is a cpp file): jmethodID xyz = (env)->GetMethodID( cls, "showxyz", "()V");

2. And I call this method as follows: env->CallVoidMethod(cls, xyz);

3. In java, my showxyz() is defined this way(this basically enables a button which was disabled) void showxyz() {findViewById(R.id.btnPass).setEnabled(true);}

And this crashes.

But I have been using this method of calling Java funcs from C using a set of GetStaticMethodID/CallStaticVoidMethod()(for nonstatic methods) and that works always.

But in this case, I have to call a non-static method and i get a crash.

View 2 Replies View Related

Android :: Error When Calling Method SetRequestedOrientation() / Fix It?

Aug 18, 2010

Code...

When the method is called setRequestedOrientation() - error. Create layout-land and placed there a copy of the main.xml file.

View 2 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 :: Calling An InputMethod Method When A BroadcastReceiver Gets Called

Feb 19, 2010

I added a BroadCastReceiver to my application.I want to call my inputMethod's method but I can't find a way to access it's instance.but I couldn't find a way to get the the InputMethod instance from the InputMethodManager.Is doing a singleton the only way to access it?

View 1 Replies View Related

Android :: Calling Superclass Method In Subclass Constructor

Apr 30, 2010

I get a NullPointerException calling a Superclass Method in Subclass Inner Class Constructor... What's the Deal?

In my application's main class (subclass of Application), I have a public inner class that simply contains 3 public string objects. In the parent class I declare an object of that inner class.

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

After I instantiate the object in the constructor, I get a runtime error when I try to assign a value in the inner class with a superclass method.

Can you not call superclass methods in the subclass constructor?

View 3 Replies View Related

Android :: How To Get Calling Activity Instance From Called Activity?

Jul 9, 2010

I have a Contact Activity which is derived from ListActivity, which displays list of contacts, and on click of item, a new Activity Message Activity derived from ListActivity is initialized.Now I know, I can pack some information in Bundle and pass it before creating activity, but is there a way I can get instance of "ContactActivity" in onCreate method of "MessageActivity"?

View 1 Replies View Related

Android :: Way To Call Another Class Method?

Aug 28, 2009

You need a reference to the class that contains the method you want to call. To access the method homepage() inside the eSkyGuide from the class Weather, you need an instance of the eSkyGuide class inside the instance of the Weather class.

View 4 Replies View Related







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