After opening embedded Unity fragment, resolution changes in parent Android app - android

I have a Unity activity embedded as a fragment inside of my Android app. Everything works fine, except that after the fragment runs, the resolution of the app is funny. And it stays that way even after restarting. I have to make a change to the AndroidManifest and then reinstall in order to get the resolution right again.
Here is a piece of the manifest from the Android app.
<application
android:name=".App"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:extractNativeLibs="true"
android:theme="#style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".FragmentActivity"
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustNothing">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Here is the entire AndroidManifest from unityLibrary that I imported into the app.
<?xml version="1.0" encoding="utf-8"?>
<!-- GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" xmlns:tools="http://schemas.android.com/tools">
<application>
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="#style/UnityThemeSelector" android:screenOrientation="fullSensor" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false">
<!--<intent-filter>-->
<!--<action android:name="android.intent.action.MAIN" />-->
<!--<category android:name="android.intent.category.DEFAULT" />-->
<!--</intent-filter>-->
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="android.notch_support" android:value="true" />
</activity>
<meta-data android:name="unity.splash-mode" android:value="0" />
<meta-data android:name="unity.splash-enable" android:value="True" />
<meta-data android:name="notch.config" android:value="portrait|landscape" />
<meta-data android:name="unity.build-id" android:value="f6e555a5-44fc-47be-9a81-b3809caa8f74" />
</application>
<uses-feature android:glEsVersion="0x00030000" />
<uses-feature android:name="android.hardware.vulkan.version" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>
Here's the activity that holds the fragment.
class FragmentActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_fragment)
}
}
Here's the fragment itself.
class UnityFragment : Fragment() {
protected var mUnityPlayer: UnityPlayer? = null
var frameLayoutForUnity: FrameLayout? = null
fun UnityFragment() {}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
mUnityPlayer = UnityPlayer(activity)
val view = inflater.inflate(R.layout.fragment_unity, container, false)
frameLayoutForUnity =
view.findViewById<View>(R.id.frameLayoutForUnity) as FrameLayout
frameLayoutForUnity!!.addView(
mUnityPlayer!!.view,
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT
)
mUnityPlayer!!.requestFocus()
mUnityPlayer!!.windowFocusChanged(true)
return view
}
override fun onDestroy() {
mUnityPlayer!!.quit()
super.onDestroy()
}
override fun onPause() {
super.onPause()
mUnityPlayer!!.pause()
}
override fun onResume() {
super.onResume()
mUnityPlayer!!.resume()
}
}
And here's R.layout.fragment_unity.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/frameLayoutForUnity"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".UnityFragment"/>
The layout for FragmentActivity is just a single fragment inside of a constraintlayout.
I hope someone can point me in the right direction because I really don't understand how screen resolution works or what controls it. But based on the appearance of layouts in the rest of the app, it feels like that's what it's related to.

I found a solution, but it's not super enlightening. What I mean is that I found a way to make the symptom stop.
For reasons I can't explain, if I set hardwareAccelerated to true inside of my app Manifest WHILE ALSO turning notchsupport to false inside the unityLibrary Manifest then my custom views stop drawing their canvases weird.
I know this seems like rain dancing or using a dowsing rod, but it works and I can revisit later to make an implementation that I understand.
Some notes: My gut feeling is that I'm letting the unity manifest talk over my app manifest and somehow turn off hardwareAccelerated, since that would explain the canvases being drawn differently. But suppressing hardwareAccelerated turning off inside the unity manifest and also forcing it as enabled in the app manifest are not enough by themselves to stop the symptom. The only thing that stops the symptom is doing all of that and also turning off notch_support. Maybe somewhere notch_support interacts with hardwareAccelerated. But I think it's more likely that there's a third factor causing all this and this random confluence of settings affects that factor happenstantially.
Edit: It's been a long time since I asked this question. But I see that it's gotten some interest recently from someone likely experiencing the same problem. I never figured out what the problem was. It sort of just happened intermittently and eventually stopped. But for the benefit of posterity I would like to say that visually detecting a change in resolution in any situation and for any cause points to a failure to accommodate different screens and is probably why the question got downvoted.
So if you're experiencing this problem too, the first place you should probably look is whether you're using px instead of dp in your custom drawn canvases. A lot of the canvas draw methods default to px and you have to normalize to dp yourself.
Also use percentages to size things out inside of ConstraintLayouts.

Related

Why is (and how to fix) my Android application triggering an onCreate (ON_CREATE) when removed from memory?

I manage an Android app for a client and am trying to detect when the app is removed from memory. I've noticed via logcat that when the app is removed from memory an ON_CREATE Lifecycle.Event is being sent. I do get an ON_STOP when the app is closed, but swiping to remove it completely from memory for some reason only generates an ON_CREATE that is additional to the original one at app launch.
I have some code that runs in Application object's ON_CREATE and can prevent it from being executed a second time if I want, but would rather prevent this extraneous event from firing. This seems wrong and I want to fix it, and get an ON_DESTROY if I can, although I've seen here on SO that sometimes it is not fired.
My Application class code looks like this:
public class ThisApplication extends Application implements LifecycleObserver
{
#Override
public void onCreate() {
super.onCreate();
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
Log.e("ThisApplication", "Inside onCreate()");
}
#OnLifecycleEvent(Lifecycle.Event.ON_STOP)
public void onAppStop() {
Log.e("ThisApplication", "ON_STOP()");
}
#OnLifecycleEvent(Lifecycle.Event.ON_START)
public void onAppStart() {
Log.e("ThisApplication", "ON_START()");
}
#OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onAppDestroy() {
Log.e("ThisApplication", "ON_DESTROY");
}
#OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
public void onAppResume() {
Log.e("ThisApplication", "ON_RESUME");
}
#OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
public void onAppCreate() {
Log.e("ThisApplication", "ON_CREATE");
}
}
As requested here is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.neimander.locus_android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-feature
android:name="android.hardware.camera"
android:required="true"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-permission android:name="android.permission.CAMERA"/>
<application
android:hardwareAccelerated="true"
android:allowBackup="false"
android:icon="#drawable/ail_logo"
android:label="#string/app_name"
android:theme="#style/MainTheme"
android:name="ThisApplication">
<service android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService" android:enabled="true" />
<activity
android:windowSoftInputMode="stateVisible"
android:name=".LoginActivity"
android:excludeFromRecents="true"
android:label="Login"
android:screenOrientation="portrait"/>
<activity
android:name="com.microsoft.aad.adal.AuthenticationActivity"
android:label="Authentication" >
</activity>
<activity
android:name=".HomeScreenActivity"
android:label="#string/title_activity_home_screen"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".GradeAssessmentActivity"
android:label="#string/title_activity_grade_assessment"
android:noHistory="true"
android:parentActivityName=".HomeScreenActivity"
android:screenOrientation="portrait"/>
<activity
android:name=".ScanningActivity"
android:label="#string/title_activity_scanning"
android:parentActivityName=".GradeAssessmentActivity"
android:screenOrientation="portrait"/>
</application>
</manifest>
In the ProcessLifecycleOwner doc, it says:
ON_CREATE will be dispatched once and ON_DESTROY will never be dispatched
So if ON_CREATE is dispatched more than once, it is a bug and you should report it to the Android Issue Tracker.
But before jumping on the bug report train, you should double check that you are registering and observing the lifecycle properly. It is more than likely that there is a silly error in the code.
Also, it is impossible to track when your app is removed from memory from within the app itself. Android may keep your application's process even when nothing is in it. Opposite to that, Android may kill your application's process with no warning.
Why are you bothering yourself with app closing? Docs describe lifecycle somewhat, when you close it you're done and you can't assume the app is working. There is even continous working mode with some drabbacks. On PC - applications that hide its instance or don't really want to close itself is called shitware. Here it is somewhat solved with lots of nonsense in the background.

Android WebView and webrtc hello world example

The code I'm pasting below was built with Android Studio and tested on an Android smartphone. I'm pretty sure it was working fine as long as I manually enabled camera and microphone permissions. I also wrote a Java variant instead of Kotlin and all worked as expected.
However, I am totally unable to make this app work anymore, no matter how many times I reboot my device or make sure there are no other running apps that might use the camera or mic.
The webrtc test site mentioned in the code works fine if I load it in Chrome.
So, any ideas why my webview "test app" cannot access any media device even if I enable microphone and camera permissions in "Android OS app settings"?
And like I said, I'm pretty sure it DID work before, but something went wrong, obviously. I just want to make sure here that the code is OK.
package org.me.test
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val WebView: WebView = findViewById(R.id.webview)
WebView.settings.javaScriptEnabled = true
WebView.loadUrl("https://test.webrtc.org")
}
}
The manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.me.test">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.test">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
</manifest>
The layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Thanks
I think I need to use the WebChromeClient if I want webrtc to work.
Something like this seems to work for me in my MainActivity class:
myWebView.setWebChromeClient(new WebChromeClient() {
#Override
public void onPermissionRequest(final PermissionRequest request) {
request.grant(request.getResources());
}
});

My Android App is Overriding The Lyft App?

I built an Android app that is somehow taking over or overriding the Lyft driver app. Basically, whenever a user has my Android app downloaded, it somehow takes over her Lyft app. She will not get any ride requests from Lyft (even during the middle of a super busy time). Then, when she deletes my app, it works perfectly again. She immediately gets rides again. It is the weirdest thing I have ever seen. And this is not just coincidental, when she goes to kill her apps, it literally shows my app logo taking over the Lyft driver app. Notice how originally it has the Lyft logo. Then, when my app is installed, it has my logo for the Lyft app (my logo is just the default Android logo). She can even kill my app, and her Lyft and also Uber driver app do not work! The only way to fix it is to completely uninstall my app and restart her phone. Then, everything works perfectly. One important element is I do track the location all the time. I'm just not really sure where even to start with this bug, so any ideas are helpful. Thanks! The user is using a Galaxy Note 10+ with Android 10. None of our other Android users have told us about this problem. It seems to be a unique case for this phone.
Here are all my manifest and intents:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.danieljones.nomad_drivers">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
<application
android:requestLegacyExternalStorage="true"
android:name=".parse.Parse"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".checkIn.CheckInActivity"
android:label="#string/title_activity_check_in"/>
<activity android:name=".insurance.analysis_activity.ZendriveAnalysisActivity" />
<activity android:name=".fare.breakdowns.FareBreakdownActivity" />
<activity
android:name=".navigation.HomeNavigationActivity"
android:label="#string/title_activity_home_navigation"
android:screenOrientation="portrait"/>
<activity android:name=".welcome.LoginActivity" />
<activity android:name=".welcome.special_code.CodeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".new_rides.ride_detail.NewRideDetailActivity" />
<activity android:name=".rides_lists.ride_detail.RideDetailActivity" />
<activity android:name=".personal_rides.ride_detail.PersonalRideDetailActivity" />
<activity android:name=".review_list.ReviewActivity"/>
<activity android:name=".user_profile.driver_card.EditProfileActivity" />
<activity android:name=".user_profile.edit_form.EditProfileFormActivity"/>
<receiver android:name=".insurance.zendrive.MyZendriveBroadcastReceiver" />
<activity android:name=".archived_rides.ride_detail.ArchivedRideDetailActivity" />
<service
android:name="com.parse.fcm.ParseFirebaseMessagingService"
android:permission="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<receiver
android:name=".push_notifications.ParseCustomBroadcastReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
</application>
I believe your issue is related to your defined name element in your Manifest.xml, specifically, the one underneath the application tag.
You have yours defined as: .parse.parse, which seems rather odd to me.
Looking at this link from the parse platform, I think that's what you are declaring as your app's name.
This name element, though it may seem unimportant, is actually where your application is generating the Application level Context from, or in this case, where the external Intents are being discovered.
It's highly likely that the system cannot distinguish which one to pull and it is therefore pulling yours over Lyft when it can.
To resolve this, just declare your own class that extends the Application class somewhere in your project like this:
public class MyApplication extends Application {
private static MyApplication sInstance;
#Override
public void onCreate() {
super.onCreate();
sInstance = this;
}
/**
* Get an instance of the application.
*
* #return {#link MyApplication}
*/
public static synchronized MyApplication getInstance() {
if (sInstance == null) {
sInstance = new MyApplication();
}
return sInstance;
}
/**
* Get context
*
* #return Context
*/
public static synchronized Context getContext() {
return getInstance().getApplicationContext();
}
}
Then just update your Manifest to look like this:
<application
.
android:name=".MyApplication"
.
.
.>
...
And it should function properly.
If you are still having troubles, update your question with more info and we can diagnose it further.

Android manifest for USBAccesory

I am making an app that communicates with a piece of usb hardware made by my company (this is the only app allowed to talk to the usb accessory, it's not a public api). I am having difficulties setting up the proper launch modes in the manifest.
There are three components to the app: the main activity, a login activity, and the USBService.
I'm assuming the intent for the main goes to the login activity, and the intent for the usb goes to the USBService, but I am not sure if I do this, will this start the service if the app is not running? More over, if it does, how do I fetch an already existing service?
What type of structure should I be looking at for the manifest file? (specifically, intent-filters, and appropriate launch modes... I've read a few documents about the launch modes but I am still not sure I quite understand... There should only ever be at most one instance of each activity/service, and they need to communicate together.
edit: it is not necessary for communications to start before the app is open, nor is it necessary to launch the app automatically when the usb is connected.
edit: my manifest as it stands, looks like:
<uses-feature android:name="android.hardware.usb.accessory" />
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="mainpackage.MainActivity"
android:label="#string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="#xml/accessory_filter" />
</activity>
<activity
android:name="mainpackage.LoginActivity"
android:label="#string/title_activity_login"
android:windowSoftInputMode="adjustResize|stateVisible" >
</activity>
<service android:name="updater.USBService"
android:exported="false" >
<!--
-->
</service>
</application>
in your manifest add
<manifest ...>
<uses-feature android:name="android.hardware.usb.host" />
<uses-sdk android:minSdkVersion="12" />
In this case, the following resource file should be saved in res/xml/device_filter.xml and specifies that any USB device with the specified attributes should be filtered:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="1234" product-id="5678" class="255" subclass="66" protocol="1" />
</resources>
Hope this help.
Your manifest looks good,
I think you make a good choice for putting the intent-filter "android.hardware.usb.action.USB_ACCESSORY_ATTACHED" in the mainActivity and start the application in this activity,
and again I think it's a good choice to start your mainActivity in SingleTop launch mode,
because if an instance of the mainActivity already exists at the top of the current task, the system going to launch this activity, no new instance of this activity will be created.
For a best understanding of the different launch mode available in android,
I think this link may help you :
http://www.intridea.com/blog/2011/6/16/android-understanding-activity-launchmode
To make a long story short I think you'll be all set with this manifest as is.
To Use Android Devices min SDK version should be set to 12 and need to declare following line in AndroidManifest.xml file
<>
<uses-sdk android:minSdkVersion="<version>" />
...
<application>
<uses-library android:name="com.android.future.usb.accessory" />
<activity ...>
...
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="#xml/accessory_filter" />
</activity>
</application>

App refuses to connect to Parse backend

I am working on an app called TobaccoRoad that uses a library project called BestApproach. It uses a Parse backend to display custom generated content and handle push notifications. Everything was working pretty alright until a few days ago, when I must have messed up some settings somewhere and it no longer seems to be making the connection to the parse systems. I'm quite sure it's a local issue, because my second tester phone, which has not had updated code pushed to it in a few days, is still receiving notifications and can view that custom content.
The weird thing is, even after clearing my workspace and starting fresh from the (definitely good) code my employer gave me, and following all the tutorials and troubleshooting guides on Parse.com (see https://parse.com/docs/push_guide#installations/Android; https://parse.com/tutorials/android-push-notifications) I'm still not connecting to Parse. I haven't made any significant changes that I can recall, so I'm at a loss as to what might be causing this.
I know it's not an issue of a bad applicationID or clientKey, because even substituting random strings into the Parse.initialize call gave the same results, and a logcat error about not being able to authenticate.
Here are the relevant bits from my manifest files, first for the library project...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bestapproach.lib"
android:versionCode="8"
android:versionName="1.6.1">
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:icon="#drawable/app_icon" android:label="#string/app_name"
android:theme="#style/Theme.BA" >
<activity android:name="com.bestapproach.lib.SplashActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation"
android:theme="#style/Theme.BA.Splash">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--Declarations for all of my Activities...-->
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
</application>
</manifest>
And the manifest is exactly the same for my dependent project, with the exception of where I define a custom receiver at the end:
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
<receiver android:name="com.bestapproach.lib.MyCustomReceiver">
<intent-filter>
<action android:name="com.bestapproach.lib.UPDATE_STATUS" />
</intent-filter>
</receiver>
And here's the code for the onCreate() method in my main activity (SplashActivity) where the Parse service is initialized:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
String parseClientId = getString(R.string.parse_client_id);
String parseAppId = getString(R.string.parse_app_id);
//debug output
Log.v("parse should be initializing...", parseAppId+" "+parseClientId);
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(this, parseAppId, parseClientId);
PushService.subscribe(this, "", MenuActivity.class);
PushService.setDefaultPushCallback(this, SplashActivity.class);
ParseInstallation.getCurrentInstallation().saveInBackground();
ParseAnalytics.trackAppOpened(getIntent());
final Activity a = this;
// Fetches content if it doesn't exist.
StoreManager sm = StoreManager.getInstance(a);
ParseStoreManager psm = ParseStoreManager.getInstance(a);
return;
}
}
Suggestions I've found that seem like they may be on track with what I need include running Parse.initialize() in the onCreate() of every activity, which I don't really want to do as there are a lot of them and that would be a lot of duplicated code, or generating an Application object and running it from there. Everything I've tried in relation to that has ended up breaking once I add it to my manifest file, due to TobaccoRoad's dependencies on the library project.
I know, it's a lot to dig through, but any suggestions would be appreciated. Thanks everybody.
Possible fix:
Change this line
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(this, parseAppId, parseClientId);
to this:
if (!("".equals(parseClientId) || "".equals(parseAppId))) {
Parse.initialize(SplashActivity.this, parseAppId, parseClientId);
the issue is that
ParseAnalytics.trackAppOpened(getIntent());
accepts the intent from that activity from your SplashActivity and from the application scope
Also, you initialize parse from the activity which we generally don't do.
We try initialize parse from the Application class so it has the context of the Application scope and not of the Activity Scope.
I recommend you to create an Application class and include the parse code in the onCreate of the Application...which you would need to do only once.
Or, you can create some BaseActivities and make all your activities in the application extend to that. This will save you from writing duplicate code...this is just in case you are bound not to create an Application class.
Pardon me for anything wrong...I am new in answering.

Categories

Resources