In my project, the AlarmManager did not work (I hung BradcastReceiver on it, which I did not call).

Created a new project with a different applicationId , wrote a separate code in it, which after a specified time would display an alert (the structure is the same: AlarmManager , BroadcastReceiver ). In the new project, everything worked.

Problem:
a) I copy the working new code into the old project - it (the code) stops working
b) I copy the idle code of the old project into a new one - it (the code) starts working
c) in a running new project, changing the applicationId to any other - stops working
d) in a non-working old project I change the applicationId to the one in the new one - it starts working

If in cases a and b it can be assumed that I forgot to indicate something in the Manifest or gradle , then in cases c and d, as far as I understand, such assumptions sound a bit absurd.

Question: how can this situation be explained - and how to deal with it? (not critical, of course, but I want to write with the old applicationId , since the alpha version already hangs in Google, and nothing has been poured into this project with the modified Id).

It is worth adding that at every moment of testing, when a project was installed on a device, all past / other versions were deleted.

// Items a, b, c, d are not related chronologically.

UPD1:

Manifest.xml

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.packagename"> <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/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".Receiver"></receiver> </application> </manifest> 

MainActivity.java

 package com.packagename; import ...; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override protected void onPause() { super.onPause(); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); Intent intent = new Intent(MainActivity.this, Receiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, pendingIntent); } } 

Receiver.java

 package com.packagename; import ...; public class Receiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent){ Log.d("abc", "here"); } } 

build.gradle

 apply plugin: 'com.android.application' android { compileSdkVersion 26 defaultConfig { applicationId "com.packagename" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' } 
  • Show me some code. Actually receiver, as alarm do, manifest and build.gradle - Yuriy SPb
  • @ ЮрийСПб added :) - Nike
  • Try adding an action for the intent receiver, also setting intent-filter in the manifest in the receiver tag. Well, you can also verify that you have the applicationId and package attribute in the manifest at the time of the first change. - YurySPb
  • @Yuriy SPb Added action, does not work. applicationId and package match. Found some materials, apparently, this problem is relevant only for some models of Huawei Honor and Asus Zenfone . I am testing on Zenfone. How to solve, I do not know . Today I will try on others. stackoverflow 1 stackoverflow 2 w3bsit3-dns.com - Nike
  • Try specifying the receiver's full name in the manifest <receiver android:name="com.packagename.Receiver"></receiver> - woesss

0