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.

Android :: method of Service does not take place immediately from inside Activity


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

Android : Access A Method Of An Activity Inside TabActivity?

Oct 1, 2010

I would like to access the public method of an Activity run by a TabActivity using: Code...

Basically, what I what is to let the parent Activity call a method in child Activity in order to do something. Is this possible?

I did try this:((TeamHuddleScreenMsgsView)getTabHost().getCurrentTabView().getContext()).refreshModel(); but I'm encountering a ClassCastException. It seems that the getContext() still gives the TabActivity. Any help on how to get the child Activity?

View 2 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 :: Cannot Call Method Of View Object Inside Activity

Nov 7, 2010

In my program I have a custom view object. Inside the view class is a method called foo. For some reason when I call foo from my activity, it doesn't fire. Here is the code:

XML of the custom view:
<com.company.application.MyView android:id="@+id/my_view" android:layout_width="wrap_content" android:layout_height="wrap_content" />

The activity code:
public class Main extends Activity { MyView mView;
/** Called when the activity is first created. */
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.main);
LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = li.inflate(R.layout.main, null); mView= (MyView) v.findViewById(R.id.my_view);
//A button to fire the method inside foo() Button switchLeft = (Button) findViewById(R.id.switch_left); switchLeft.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { callTest(); } } );
} public void callTest() { Log.w(this.getClass().getName(), "clicked left arrow");
mView.foo(); mView.postInvalidate();
} }

Finally here is foo:
public void foo() { mBackground = mContext.getResources().getDrawable(R.drawable.temp_canvas); Log.w(this.getClass().getName(), "background set");
}

The first log is always written when the button is pressed, but the second log is not because foo never fires. What is the deal here? Upon request, the full view

public class MyView extends View { Drawable mBackground; Context mContext;
public MyView (Context context) { super(context); mContext = context;
mBackground = mContext.getResources().getDrawable(R.drawable.leftarrow1);
} public MyView (Context context, AttributeSet attrs) {
super(context, attrs); mContext = context;
mBackground = mContext.getResources().getDrawable(R.drawable.leftarrow1);
} public void foo() { mBackground = mContext.getResources().getDrawable(R.drawable.temp_canvas);
Log.w(this.getClass().getName(), "background set"); }
@Override public void onDraw(Canvas canvas) { Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL); // draw a solid blue circle
paint.setColor(Color.BLUE); canvas.drawCircle(20, 20, 15, paint);
// draw a test background mBackground.setBounds(0, 0, 300, 400);
mBackground.draw(canvas); }
}

View 1 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 :: 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 :: 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

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 :: Place View Inside FrameLayout

Oct 3, 2010

I want to add a view inside a FrameLayout programmatically and to place it in a specific point within the layout with a specific width and height. Does FrameLayout support this? If not, should I use an intermediate ViewGroup to achieve this? My initial idea was to add an AbsoluteLayout to the FrameLayout and place the view inside the AbsoluteLayout. Unfortunately I just found out that AbsoluteLayout is deprecated.

View 2 Replies View Related

Android :: Place An Animated Image Inside An EditText That We Can Show And Hide?

Sep 14, 2010

I am trying to add an animated spinner inside a EditText view to the right. And programmatically show/hide it.

I have created the animated spinner by introducing a linear interpolation rotation. code...

View 2 Replies View Related

Android :: Problem While Place Radio Buttons Inside Liview In Droid / Fix It

Jun 17, 2010

I have a listview with radio button. when i click any option and scroll that list view the previous select will cleared.How to do this. The actual problem is when scroll the view on every scorll the view is refreshed, that's why every time the view is refreshed. How to do this I can't get any solution.

View 1 Replies View Related

Android :: Detect When User Drag Finger From Any Place In Screen To Inside Of ImageView?

Nov 18, 2010

I've an ImageView in a LinearLayout, how can I detect when user drag his finger from any place in the screen to inside of ImageView?

View 1 Replies View Related

Android :: Change Market Payment Method / Place To Go To Do So?

May 10, 2010

Anyone know if there is a way to change your payment info for the android market app?

Is this an automatic thing where if you try to buy something and your credit card you entered last time is expired, it will automatically ask you for new info?

Anyway, i can't find a place to go to change the info.

View 1 Replies View Related

Android :: Sending A String Created Inside A Method To Another Class

Sep 12, 2010

I have code which has one activity which passes information to a second activity.
I can use this information to pass to a third activity with additional information from the result of the second activity.

I want to use gestures as a method of going back to a previous activity, but if I go back from the third to the second activity I need the information initially passed from the first to the second activity to still be present.

i.e.

First Acticity

what is Y?

answer y = 5

Second activity

User said Y = 5

what is X?

Third Activity

User said Y = 5
X = 6

Go back to Second activity but maintain the input of

User said Y = 5.

To do this I have used a bundle to pass the information between activities, but I can only access the info in the bundle from within a method within the class started by the intent.

The gesture controls are within another class, so I cannot access the bundle information from within this class as the getIntent command produces a not defined error.

What I need to do is to be able to pass the information from the bundle from the first activity to the gesture class so that I can pass it back when I go back using the gestures.

View 1 Replies View Related

Android :: How To Get Activity View Inside That Activity?

Nov 11, 2010

I want to show my next activity withing my previous activity layout "LinearLyout". But it is not working. Can any one help? I put my last activity layout reference to a global class in an static variable. My code...

View 3 Replies View Related

Android :: Android: Why Doesn't Activity Appear Immediately After Calling StartActivityForResult

Sep 25, 2009

The application I'm currently working on consists of several dialogs and there is an issue with one dialog I still haven't found the cause.

Running the debugger the execution reaches the following two lines:

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

And then the onCreate() method in DlgLogin class executes as well

But the login dialog doesn't appear. If I leave the device idle for such long period of time that the screen turns off and then press any button on the device to turn it on the login dialog appears.

The dialog of course should appear immediately but so far haven't found the cause of the problem.

View 1 Replies View Related

Android :: Can WebView Be Used Inside A Service?

Oct 9, 2009

I want to run part of my app logic in a background service. However, much of the app uses JavaScript.Currently I run the JavaScript inside a WebView.Is it possible to have an invisible WebView while running inside a Service?If the answer is no, is there any way to run JavaScript inside a Service?

View 4 Replies View Related

Android :: Place One Activity On Another?

Aug 11, 2010

I have an task to set horizontal swipe tabs below the header,how can i set an activity on another activity.

View 3 Replies View Related

Android :: Accessing Ringer Mode Does Not Work Inside Service

Jul 9, 2010

I have an application that creates a notification with sound when a specific text comes in. To do this, I detect the current ringerMode, change the ringerMode to normal, play the sound, and then quickly return the ringer back to its original setting.

View 1 Replies View Related

Android : Way To Stop GPS Inside An Activity

Aug 12, 2010

Currently working on a simple app to allow users to find various things around them. When the activity that shows the Google map is active I can see the GPS icon on the status bar, which is normal. But I need to be able to stop the GPS hardware when my user navigates away from the activity, and switch the GPS back on when the activity is shown.

Is there a simple way to stop GPS when a user navigate away from an activity? I have tried the LocationManager's removeUpdates() but this doesn't actually stop the GPS (the icon is still flashing on the status bar and draining the battery).

What I'm looking for is a simple way to programatically stop the GPS hardware.

View 2 Replies View Related

Motorola Droid X :: Bad Service Inside Certain Buildings

Oct 23, 2010

I get bad service at certain buildings. I'm in target store right now and service is ridiculously bad

View 16 Replies View Related

Android : Closing Activity Completely / Process Killed By Activity Manager Service

Aug 2, 2010

Whenever the memory needs to be reclaimed, the process is being killed by Activity Manager Service in killPidsForProcess. I have a back button in my activity window on right corner of the title bar.

I want to kill the activity completely on clicking the close button. Can I reuse the same function and will it have any major effect? Please help me out in this.

View 3 Replies View Related

Android :: Add Activity Indicator Inside An Alert?

Nov 24, 2010

Is it possible to add an activity indicator as a part of an alert. i need this bcos it is difficult to show alert view in white background.

View 1 Replies View Related

Android :: Display Widget Inside Activity?

Jun 2, 2010

I was wondering if there is a way to show a widget that I have created inside an activity. I have a weather widget and I also have an app I am working on that I would like to include weather reports in. Is there a way I can just re-use the widget code and make it show inside the weather activity?

View 4 Replies View Related

Android :: Why Service Connection Method Never Executed?

Sep 28, 2010

This is the class that calls my Service:

public class TicketList extends ListActivity {
private ArrayList<Tickets> alTickets = new ArrayList<Tickets>();
private boolean listCreated = false;
private static Drawable background = null;
private Resources res;
private Tickets ticket = null;
private TicketConnector localService;

[Code]

Here is the output of LogCat at verbose mode while activating the TicketList Activity:

09-28 23:22:11.420: INFO/ActivityManager(795): Starting activity: Intent { cmp=org.mw88.cmdb/.gui.TicketListActivity }
09-28 23:22:12.340: WARN/ActivityManager(795): Binding with unknown activity: android.os.BinderProxy@4410bf30
09-28 23:22:16.090: INFO/ActivityManager(795): Displayed activity org.mw88.cmdb/.gui.TicketListActivity: 4606 ms (total 4606 ms)

View 1 Replies View Related

Android :: How To Embed External Activity Inside One Of Mine?

Nov 22, 2010

I need an Activity showing a specified PDF and two buttons. Is possible to embed an external PDF viewer - showing a specified URI - inside the view of my application? How can I do it?

View 5 Replies View Related

Android :: Put Camera Preview Inside A Surfaceview In An Activity Xml Gui

Aug 27, 2009

I just got my camera preview working for my app, but it is not appearing where I want it to appear, and I'm not sure how to get it there. Instead of using the entire screen for the preview, I would like to put it inside a surfaceview in an activity xml gui. What do I need to change? Here is my code:

public class TakePic extends Activity {

SurfaceView camSurface;

Preview camPreview;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);//hide window title

camPreview = new Preview(this); //create preview

setContentView(R.layout.takepic);

setContentView(camPreview); //set preview as activity content

camSurface = (SurfaceView) findViewById(R.id.camsurface); }

View 5 Replies View Related

Android :: Start An Activity Inside Any Layout In Droid?

Sep 24, 2010

I have created a an activity named Example which have 3 LinearLayouts . I want to start an activity. So I used the following lines of code...

Test is another activity. As a result of the above code a new activity is called in new page. But I want to get the same resule or start the activity inside 2nd layout of Example class.

How to achieve this.

View 1 Replies View Related







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