I have an app that use with web service.
The action with the web service maybe will take a few seconds, when i search in google a way for handler with this concept i saw that i can use AsyncTask or new Thread.
I explain my basic action app. In the MainActivity i have two fields username and password. The MainActivity get from the user the inputs and send those inputs to function in ActionClass and there I use with WSClass. In the function class i sent to web service and wait to the response.
- How can i create the white circle when the user wait to my actions app?
- What the best option to use?(AsyncTask/new Thread)
MainActivity:
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
ActionClass = ActionClass.getInstans();
ActionClass.setContext(this);
ActionClass.login("username","password");// in the future in put a PlainText for username and password.
if(isLogin == true)
{
//here i move to another activity....
}
}
}
public class ActionClass
{
public void setContext(Context context) {
if (this.context == null) {
this.context = context;
WSClass = new WSClass();
}
}
public static ActionClass getInstans() {
if (instans == null) {
synchronized (ActionClass.class) {
if (instans == null)
instans = new ActionClass();
}
}
return instans;
}
public boolean login(String username, String password) {
{
WSClass.loginWs(url,username, password, object.class);
}
}
public class WSClass
{
public <T> T login(String URL,String username,String password,
Class<T> output)
{
//...Do Something...
}
}
Update the qustion
The WsClass use with generic function that get and return <T>
variable.
After i checked the AsyncTask... AsyncTask can be use as generic if not how can i resolve this?
The function in WSClass updated above.
Thanks,
Tal