[android-beginners] Problem with service

2009-10-29 Thread Nick D.

Hi everybody.

I'm new to android programming and I'm currently trying to build a
basic app that will take some user input and at the press of a button
parse the input using a service and then send it back to the
activity to be printed onto the screen. My problem is that it seems
like the screen is only updated when I click on the text box. Also,
I'm trying to print from the activity by calling an activity function
in the service and none of the is being printed on the screen. Can
anybody take a look at the code and tell me what your think?

Any help would be much appreciated

package com.NickD;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class p1 extends Activity implements OnClickListener {
/** Called when the activity is first created. */

EditText portText;
static TextView tv;
public static int port = 0;
public static String request = empty;
public static boolean newIPReady = false;
Context tContext = this;

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button button = (Button)findViewById(R.id.Button01);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
 // do something when the button is clicked
   portText = (EditText)findViewById(R.id.EditText01);
   try {
port = 
Integer.parseInt(portText.getText().toString());
}
catch(NumberFormatException obj) {
//handle text entry non numerical
}

Intent serverServiceIntent = new Intent(tContext,
ServerService.class);

serverServiceIntent.setAction(com.NickD.ServerService);
startService(serverServiceIntent);

}
});

tv = (TextView)findViewById(R.id.DisplayedData);

} //onCreate()

// Implement the OnClickListener callback
public void onClick(View v) {

} //onClick()

public static void newIP(String s) {
tv.append(IP Address Here);

} //newIP

} //OnClickListener()









package com.NickD;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;



public class ServerService extends Service {

ServerSocket sSocket;
Socket socket1;
String s;

@Override

public IBinder onBind(Intent intent) {

return null;

}

private Timer timer = new Timer();
@Override

public void onCreate() {

super.onCreate();
Toast.makeText(this,Service created ..., 
Toast.LENGTH_LONG).show
();
startService();
} //OnCreate()


private void startService() {

timer.scheduleAtFixedRate(new TimerTask() {

@Override
public void run() {
p1.tv.append(run\n);
p1.newIP(s);
// TODO Auto-generated method stub
/*try {
sSocket = new ServerSocket(p1.port);
Socket socket1 = sSocket.accept();
InputStream in = socket1.getInputStream();
p1.request = changed;

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/

}

}, 0, 1); //Interval
}// listen()

@Override

public void onDestroy() {

if (timer != null) {
timer.cancel();
}

super.onDestroy();
Toast.makeText(this, Service destroyed ..., Toast.LENGTH_LONG).show
();

}

}


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

[android-beginners] problem with service

2009-08-26 Thread Imran

Hey All,

  I have a service which should download files in background, i am
calling this service form another activity,
  the problem is when i am calling this service form another
Activity the present Activity is getting Freezed( i.e not able to get
control back ) until the all files in service are downloaded.

  once all the files in the service are downloaded the activity is
getting the control back.

what i want is the the service should download all the files in
background with effecting the Activity which called the service.

Help me Guys..!!

Thanks,
Imran

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---