first I apologize for my poor English. I'm just approaching to Parse.com
and I'm developing a "multi-server" application that allows me to send notifications filtered by "server".
I tried two solutions but both have some issue all connected to the fact that when i start my Application i don't know which "server" the user will choose.
Idea 1 - Real Multi Server
- I create manually n
Parse.com
servers, totally separated each other - I store all my servers keys in objects like
[Name, AppID, clientKey]
- My application lists the name attribute
- The user choose his server
I start new
Activity
in whichonCreate()
I initialize Parse like:String appID = getAppID(); String cKey = getKey(); Parse.initialize(this, appID, cKey); ParseInstallation.getCurrentInstallation().saveInBackground();
(If he want to change server i simply clean my App data and re-initialize Parse with the new keys)
- Everything works fine until I try to send a Push Notification when the the app is closed (not active and not in background) when I have a
NullPointerException
due to initialization of Parse not yet called.
Idea 2 - Simulated Multi Server
- I create manually ONE
Parse.com
server - All tables have a new Column like (just as example)
uniqueIdServer
I initialize Parse in Application like:
public class MyApplication extends Application { @Override public void onCreate() { Parse.initialize(this, "ThisTimeIHaveJustOneAppIDIt'sEasy", "SameHere"); ParseInstallation.getCurrentInstallation().saveInBackground(); super.onCreate(); }}
I display my old list but this time is just [name, uniqueID]
- The user choose his "server"
- Now i can easy filter my data with my new column and i have no problem when my app is closed because Parse will call his initializer by his own
- But i don't know how i can filter Push Notification just for some
uniqueId
I tried using channels and than sending Push only at that channel:
List<String> channels = new ArrayList<>(); channels.add(getUniqueID()); ParseInstallation install = ParseInstallation.getCurrentInstallation(); install.put("channels", channels); install.saveEventually();
But is always the same, i dont know at "Application time" what my user will choose so my
getUniqueID()
will bind"null"
or similar and even worse i don't know how can i change channel (atm i can only if i uninstall my app)
Really thanks at all, any help will be really appreciated.