Hi,
I want to show notification in service..!
While I click button in my home screen I just call
service.!
That service run every 30 seconds with the help of
timer..! I want to show result to user..!
How can I implement this..! Herewith I attached
code..
HOme screen
----------------------
package com.servicetest;
import java.util.Timer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class Home extends Activity
{
private Button btn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button)findViewById(R.id.Button01);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Hai",
Toast.LENGTH_SHORT).show();
Intent in = new Intent();
in.setClassName("com.servicetest",
"com.servicetest.ServiceTest");
startService(in);
}
});
}
}
ServiceTest.java
-----------------------
package com.servicetest;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class ServiceTest extends Service
{
private Timer timer = new Timer();
private static final String TAG = "MyService";
MediaPlayer player;
WebserviceConnect wsConnect = new WebserviceConnect();
String result = "";
boolean flag = true;
private long delay = 1000;
public static final int NOTIFICATION_ID_RECEIVED = 01221;
@Override
public IBinder onBind(Intent intent)
{
return null;
}
@Override
public void onCreate()
{
Toast.makeText(this, "My Service Created",
Toast.LENGTH_LONG).show();
Log.d(TAG, "onCreate");
}
@Override
public void onDestroy()
{
Toast.makeText(this, "My Service Stopped",
Toast.LENGTH_LONG).show();
Log.d(TAG, "onDestroy");
}
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "My Service Started",
Toast.LENGTH_LONG).show();
Log.d(TAG, "onStart");
timer.scheduleAtFixedRate(new TimerTask()
{
@Override
public void run()
{
// TODO Auto-generated method stub
result = wsConnect.Connect("CheckStatus", "ID",
"7x897");
Log.d(TAG,result);
}
}, delay , delay);
Log.d(TAG,result);
Toast.makeText(getApplicationContext(), result, 5).show();
if (result.equals("Success"))
{
timer.cancel();
timer = null;
}
}
}
Thanks & Warm Regards,
Gold
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en