Now that you've created the main application class, you need to use it. The
MainActivity will create a connection to the repository, and create a
session object. This session object will be stored in the application context, so it can be
accessed from other activities in your application.
- Load MainActivity.java into the Eclipse editor.
- Add the property private TestApp1Application app; to the class.
- Locate the try statement in the class ConnectToRepo.
-
Replace the following code:
try { // connect to on-premise repo RepositorySession session = RepositorySession.connect(url, username, password); // this line already in the code ...
With the code below:
try { // get application context app = (TestApp1Application) getApplication(); // connect to on-premise repo RepositorySession session = RepositorySession.connect(url, username, password); // save session in application context app.setSession(session); // subsequent code remains unchanged ...
This retrieves the application context into the app variable. Once the session object is obtained, this is saved into the application context using the setter method you created in the application class.
-
Save your changes. If you have an error at this point, check you have imported the
Application class using the following import statement:
import com.alfresco.tutorials.testapp1.TestApp1Application;
- Check your changes by running your application. It should run, although there are no changes to core functionality as yet.