You cannot create an object like that from your service. I think you are new to Java. When you do CheckActivity check = new CheckActivity()
a new instance of your CheckActivity
is created and no doubt it will return zero. Also you should never try creating objects of activities like this in android.
As far as your question is concerned you can pass your editText value to your service via a broadcast receiver.
Have a look at this.
Also if you have the editText value before creating the service you can simply pass it as intent extra , else you can use the broadcast approach.
In your service
broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equalsIgnoreCase("getting_data")) {
intent.getStringExtra("value")
}
}
};
IntentFilter intentFilter = new IntentFilter();
// set the custom action
intentFilter.addAction("getting_data"); //Action is just a string used to identify the receiver as there can be many in your app so it helps deciding which receiver should receive the intent.
// register the receiver
registerReceiver(broadcastReceiver, intentFilter);
In your activity
Intent broadcast1 = new Intent("getting_data");
broadcast.putExtra("value", editext.getText()+"");
sendBroadcast(broadcast1);
Also declare your receiver in onCreate of activity and unregeister it in onDestroy
unregisterReceiver(broadcastReceiver);