Notification opening duplicate activity - java

I've implemented OneSignal to send push notifications to my Android app. I've mainly implemented everything using their REST API and didn't do much code work in my app. I've followed (and literally copied the code as there was no need for much changes) this documentation.
The problem is, when I'm using my app in foreground (mainactivity of my app) and I send a notificaition (which is supposed to launch the updateactivity), the activity opens on top of the current activity. Now, even when I'm tapping Exit from my app's menu, it's closing the activity on the top, however, the activity on the bottom is still there. So, basically, users have to exit from the app twice.
I have declared all activities as <singleTask> in the manifest.
Here's the ApplicationClass.java needed and used by OneSignal:
package com.application;
import android.app.Application;
import com.onesignal.OneSignal;
#SuppressWarnings("unused")
public class ApplicationClass extends Application
{
#Override
public void onCreate()
{
super.onCreate();
OneSignal.startInit(this)
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
.unsubscribeWhenNotificationsAreDisabled(true)
.init();
}
}
And here's my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.application"
android:installLocation="auto">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".ApplicationClass"
android:allowBackup="true"
android:fullBackupContent="#xml/backup_descriptor"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:ignore="AllowBackup">
<activity
android:name=".SplashActivity"
android:theme="#style/Splash"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="domain.tld"
android:scheme="http"
android:pathPattern="/*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="domain.tld"
android:scheme="https"
android:pathPattern="/*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="www.domain.tld"
android:scheme="http"
android:pathPattern="/*"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="www.domain.tld"
android:scheme="https"
android:pathPattern="/*"/>
</intent-filter>
</activity>
<activity
android:name=".SplashActivity2"
android:theme="#style/Splash"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="domain.tld"
android:scheme="http"
android:pathPrefix="/folder"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="domain.tld"
android:scheme="https"
android:pathPrefix="/folder"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="www.domain.tld"
android:scheme="https"
android:pathPrefix="/folder"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data
android:host="www.domain.tld"
android:scheme="http"
android:pathPrefix="/folder"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:launchMode="singleTask"/>
<activity
android:name=".UpdateActivity"
android:launchMode="singleTask"/>
<activity
android:name=".ErrorActivity"
android:launchMode="singleTask"/>
</application>
</manifest>
So, what to do to so that the new activity that opens because of the notification gets like merged into the current activity so that, when a user tries to exit, he/she can exit the app in one go?

Related

How to make my Android app appear in the app chooser when clicking an email link in a WhatApp chat

I'm building an Android app that I want to appear in the app chooser when clicking an email address in a WhatsApp chat.
I tried various intent filters and even tried to change my app id in the gradle file since I read here that WhatsApp whitelists some apps, but none of this solution worked.
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SENDTO"/>
<data android:scheme="mailto"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<data android:mimeType="*/*"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE"/>
<data android:mimeType="*/*"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<data android:scheme="mailto"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
applicationId "com.google.android.gm.test"
I expect that when I click an email address sent to me in a WhatsApp my app will appear in the app chooser, but it doesn't.
Does anyone have any input?

Multiple Same Apps and Deep Linking

I have implemented deep linking in my app. I added this intent filter in my manifest file, and the deep linking is working fine.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:host="xxxxxxxx"
android:scheme="xxxxxxxx" />
</intent-filter>
The problem is that through deep linking, when i click on my App, it is showing similiar kinds of apps.
It is happening when Open by DEFAULT is not set
But when the open by default is set then everything is working fine.
Try this way ..
Suppose when user call http://example.com that time my Mainactivity open then all required attribute define inside mainactivity.
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name = ".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http"
android:host="example.com"/>
</intent-filter>

How to run last viewed activity after resume?

I've got an android application. If I go through activities(for example MainTabActivity->SearchMapActivity->ListBranchesActivity) and then hide(not close) my application, android will run the main (MainTabActivity) activity after reopen. If I press "back" button, android will show me the last activity (ListBranchesActivity). How can I make my app show the last activity after resuming? I really have no idea how to achieve that. Somebody says to add singleTask statement to manifest.
My manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo"
android:largeHeap="true" >
<activity
android:name=".SearchMapActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".UpdateActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".CompanyInfoActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".FullMapActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ListBranchesActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ListCompaniesByBranchActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SearchResultActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".MainTabActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Also that thing doesn't happen everytime. Sometimes it shows last activity, sometimes - main activity.
> Also that thing doesn't happen everytime. Sometimes
> it shows last activity, sometimes - main activity.
Sometime android closes your app if it needs memory. So even if you hide(not close) ...[the] application, it might have been closed anyway

Intercepting a url to launch application

I am trying to intercept a url so that my application opens up when user accesses the URL. I am following this answer in a related question https://stackoverflow.com/a/2958870
I've added the following in AndroidManifest.xml
<activity
android:name="com.myapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<data android:scheme="http" android:host="myapp.com"/>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And have the following in onCreate of MainActivity.java
Uri data = getIntent().getData();
//String scheme = data.getScheme();
//String host = data.getHost();
if (data == null)
Log.d("Data is null", "");
else
Log.d("Data is not null", "");
When I launch the app in the emulator I am noticing that the "Data is null" debug message is coming. I had to comment out the scheme and host because that was causing my application to fail on load time and the reason for I guess was because data was null.
Am I missing something or doing something wrong?
Edit: I've tried splitting the intent-filter like this:
<activity
android:name="com.myapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="myapp.com" android:scheme="http" />
</intent-filter>
</activity>
Also, when I just have one intent-filter (below) my app does not even launch on the emulator when I press run in android studio.
<activity
android:name="com.myapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="myapp.com" android:scheme="http" />
</intent-filter>
</activity>
Try this intent filter instead:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="myapp.com" android:scheme="http" />
</intent-filter>
This is an implicit intent, but I tried it and it worked for me. I think you need the android.intent.category.BROWSABLE category.

Launch activity when google.com opened in browser

I am trying to launch my activity when google.com is navigated to in the browser, but it is not working. Here is my manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.myapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data
android:scheme="http"
android:host="google.com"/>
</intent-filter>
</activity>
</application>
Anyone see what's wrong?

Categories

Resources