0

How to synchronize data between an account and a web server in android?

I have created a project where I am trying to create an account of my own and through that account I want to get the server data after a specific amount of interval period. So far, I have googled, I have found this useful link

which tells me a lot. But I can't have a clear idea of the steps what to do for my project. I will certainly appreciate any help or suggestions. Here is what I have done to create my account:-

    public void onClick(View arg0) {
//              startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
                str1 = ed1.getText().toString();
                str2 = ed2.getText().toString();
                if ((str1.matches(""))||(!str1.contains("@myapp.com"))) {
                    Toast.makeText(MainActivity.this, "Invalid type of User email id!", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (str2.matches("")) {
                    Toast.makeText(MainActivity.this, "You did not enter a password", Toast.LENGTH_SHORT).show();
                    return;
                }
                Account account = new Account(str1, "com.example.accountMy");
                String password = str2;
                AccountManager accountManager = AccountManager.get(context);
                boolean success = accountManager.addAccountExplicitly(account, password, null);
                if(success){
                    Toast.makeText(MainActivity.this, "Myapp Account Created!", Toast.LENGTH_LONG).show();
                }else{
                    Toast.makeText(MainActivity.this, "Account is not Created!", Toast.LENGTH_LONG).show();
                }
            }});

and I have used Customauthenticator and AcountauthenticatorService class to authenticate my account. Please advice.

Community
  • 1
  • 1
user3673503
  • 385
  • 2
  • 6
  • 14

1 Answers1

0

To sync with server you need to extend the AbstractThreadedSyncAdapter class and override the onPerformSync method. It this method you should get the data from the server and insert into your content provider. check this link for complete code.

null pointer
  • 5,874
  • 4
  • 36
  • 66
  • Thanks bill gates. I am looking into your advised link and certainly going to mark it right if I pass. Please, help me with some more details if you can. Thanks again. – user3673503 Jul 08 '14 at 10:05