How to work with two accounts in one application

We are creating an Android launch with several pre-installed applications. These applications are actually part of the same code, but for the user, and in the future, these applications are different logical units.

We work with Parse Core and would like to split the data into two different logical applications. It can be done?

We decided to call "Parse.initialize" with different keys for applications and clients several times, but how can we move on to reports in different applications?

Thanks.

+7
android
source share
2 answers

I ran into the same problem a few months ago. At least I did not develop a launcher. So, I post my solution to the problem below.


Note. You cannot do this with the Parse SDK


So, the solution is to do this by opening your applications to your APIs. This has several advantages, for example, your parsers may belong to different accounts, but do not violate the terms of use of Parse.

TL; DR

Create two different applications and lay out the API using the cloud code. Use the REST client to transfer data back and forth.

Complete solution

The first step is to create two parses that you think match the individual needs of your software to run. You can generate express servers for both applications. Essentially, the result of this step is that you will have two different applications that will use your own APIs.

Now get rid of the Parse SDK, which you are probably using at the moment. Choose the right REST client, in my case it was retrofit . Configure it so that it can use different base URLs for individual calls. The following is a specific example of Retrofit.

Function that returns a REST adapter with a base URL

public FirstAppApi getFirstAppApi() { return new RestAdapter.Builder() .setEndpoint("http://app-one.parseapp.com/") .build() .create(FirstAppApi.class); } 

In this example, FirstAppApi is essentially the Retrofit interface. Similarly, you can also create an adapter for the second parsing. Now, to make a data transaction, you just need to decide which application you should use. See a few examples below.

 // Get an author from the first Parse app Author author = getFirstAppApi().getAuthorByName("Shakespeare"); // Get books of the author from the second Parse app List<Book> books = getSecondAppApi().getBooksByAuthor(author); 

In this implementation, you need to take care of a few things. The API is publicly exposed, although the name of the application, and therefore the base url, is known only to you. Therefore, the API should be well protected at termination. You should double the confirmation to the Parse guys that this does not violate their terms of use.

0
source share

I think you can try repackaging the Parse SDK jar files with the jarjar tool .
Another way is to get the Parse SDK source code (it opens) and reorganize it (change the package name).

After that, you can work with two Parse accounts using different classes:

 com.parse.Parse.initialized(); com.parse2.Parse.initialized(); 

If you are using Parse offline storage, only the second option is available. But you must also change the database name for the second Parse instanse (com.parse2.Parse). You need to change com / parse2 / OfflineSQLiteOpenHelper.java

 /** package */ class OfflineSQLiteOpenHelper extends ParseSQLiteOpenHelper { // ... /** * The SQLite Database name. */ private static final String DATABASE_NAME = "ParseOfflineStore2"; // <===== private static final int DATABASE_VERSION = 4; 
0
source share

All Articles