I have a ready application consisting of a receiver and 3 services, the main work is performed in the background. Activity registered in the manifest. Here is the Activity code:

 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } 

Those. There is a shortcut in the tab of the application, it can be tampered there, and the Activity window appears at startup. There is nothing in it, but in my opinion it is superfluous. So the question is: is it possible to launch BroadcastReceiver 's, and its correct operation without the MainActivity class, which inherits from the Activity (so that this window does not exist)? And how to do it? Already asked this question, but in the comments - they said to issue in the form of a separate question.

Manifest.xml :

 <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> <uses-permission android:name="android.permission.READ_SMS"/> <uses-permission android:name="android.permission.SEND_SMS"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <receiver android:name="com.example.smsreciv.SMSReceiver" class="com.example.smsreciv.SMSReceiver" android:exported="true" android:enabled="true"> <intent-filter android:priority="100" > <action android:name="android.provider.Telephony.SMS_RECEIVED" /> </intent-filter> </receiver> <service android:name="MyService"></service> <service android:name="SmsService"></service> <service android:name="MtsSmsService"></service> <service android:name="MTSEXTService"></service> <service android:name="TranzService"></service> <activity android:name="MainActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> 

  • depending on what the receiver does. If nothing is related to the activation, then you can delete both the MainActvity class itself and its tag in the manifest. - Vladyslav Matviienko
  • one
    Yes, I did it at the beginning, I just removed it from the manifest, but in the process of testing the application, it sometimes did not perform its functions, when I returned everything started to work, and then I decided not to experiment and ask on the forum. - FFFNikolay

1 answer 1

Yes you can. It is enough to declare the receiver in the manifest with the attributes exported=true and enabled=true , and start the service in the onReceive() receiver.

Second way to hack: declare the attributes of the Theme.Translucent.NoTitleBar transparent Theme.Translucent.NoTitleBar - then it will be invisible and does not hurt anyone.

If it is required that the service starts without a receiver, then it will be necessary to catch the Broadcast android.intent.action.BOOT_COMPLETED and put the launch of the service on it.

Update

Oops, this only works in Android version 3.1. Newer versions require that an Activity be launched. So what remains is the option with transparent activity.

  • one
    Yes, everything is correct, Activiti does nothing in the application, and does not start, the service call occurs in the receiver's onReceive (). So, after entering the attributes exported = true and enabled = true to the receiver, I can remove Activiti from the manifest and everything will be fine? I thought about transparency before, but if it is possible to remove it, there is nothing. Thank. - FFFNikolay
  • one
    I remove the activation from the manifest, install the application, and the receiver is not running, the scoundrel sleeps. - FFFNikolay
  • The manifesto added to the question how to remove the activation so that the receiver starts up without it? - FFFNikolay
  • 2
    @FFFNikolay see update - Barmaley
  • one
    Got it. So we are going as they went with a transparent window. Thank. By the way, it seems that it was because of this that my first receiver did not work on version 4.3, but it worked on 2.3.3 - FFFNikolay