Android Question [CLOSED] How to change Main to MainActivity

Jmu5667

Well-Known Member
Licensed User
Longtime User
EDIT: See this instead https://www.b4x.com/android/forum/t...like-with-a-library-like-mainactivity.102965/


We are developing a replacement app on a device. the device has an SOS button on it. When the button is pressed the existing app on the phone is launched. We have permission from the Manufacturer (China) to install our own version of the app. The manifest file should look like this :

B4X:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.onekeysos">

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />

    <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>
        <activity android:name=".OneKeySosCountDownActivity"
            android:label=""
            android:theme="@style/Theme.Transparent">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
    </application>

</manifest>


The problem we have is that in B4a the MainActivity is main, so when the button is pressed on the device our replacement app cannot be called. We engaged a Java consultant to look at this for us, and he developed a replacement sample as proof of concept and the above manifest is from his project that is wrote in Android Studio.

We want to keep all our code in b4a so we dont need to reply on a 3rd party for mods/changes. I have tried to add MainActivty and modified my manifest :

B4X:
<?xml version="1.0" encoding="utf-8"?>
<manifest
   xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.android.onekeysos"
   android:versionCode="5"
   android:versionName="1.5.19.02.20.01a"
   android:installLocation="internalOnly">
 
   <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
   <supports-screens android:largeScreens="true"
       android:normalScreens="true"
       android:smallScreens="true"
       android:anyDensity="true"/>
   <uses-permission android:name="android.permission.VIBRATE"/>
   <uses-permission android:name="android.permission.WAKE_LOCK"/>
   <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
   <application
       android:icon="@drawable/icon"
       android:label="Atlas SOS Now"
       android:supportsRtl="true"
       android:theme="@style/DarkTheme">
       <activity
           android:windowSoftInputMode="stateHidden"
           android:launchMode="singleTop"
           android:name=".main"
           android:label="Atlas SOS Now"
           android:screenOrientation="unspecified">
           <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
         
       </activity>
       <service android:name=".starter">
       </service>
       <receiver android:name=".starter$starter_BR">
       </receiver>
       <service android:name=".svc_intent">
       </service>
       <receiver android:name=".svc_intent$svc_intent_BR">
         
           <intent-filter> <action android:name="android.intent.action.START_SLIDETO_SOSSERVICE"/></intent-filter>
       </receiver>
       <activity
           android:windowSoftInputMode="stateHidden"
           android:launchMode="singleTop"
           android:name=".mainactivity"
           android:label="Atlas SOS Now"
           android:screenOrientation="unspecified">
         
           <intent-filter>
             <action android:name="android.intent.action.MAIN"/>
             <category android:name="android.intent.category.LAUNCHER"/>
             </intent-filter>
       </activity>
   </application>
</manifest>



Any suggestions ?

Regards

John.
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Add this to the manifest editor to cause a different activity (Act2) to be the launched activity:

B4X:
AddReplacement(           <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>,  )
           
AddActivityText(Act2, <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>)

Note that it will not work in debug mode.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Add this to the manifest editor to cause a different activity (Act2) to be the launched activity:

B4X:
AddReplacement(           <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>,  )
          
AddActivityText(Act2, <intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>)

Note that it will not work in debug mode.

Ok, I will try this, thank you.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
would this be the correct output ?

B4X:
<?xml version="1.0" encoding="utf-8"?>
<manifest
   xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.android.onekeysos"
   android:versionCode="5"
   android:versionName="1.5.19.02.20.01a"
   android:installLocation="internalOnly">
   
   <uses-sdk android:minSdkVersion="5" android:targetSdkVersion="26"/>
   <supports-screens android:largeScreens="true"
       android:normalScreens="true"
       android:smallScreens="true"
       android:anyDensity="true"/>
   <uses-permission android:name="android.permission.VIBRATE"/>
   <uses-permission android:name="android.permission.WAKE_LOCK"/>
   <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
   <application
       android:icon="@drawable/icon"
       android:label="Atlas SOS Now"
       android:supportsRtl="true"
       android:theme="@style/DarkTheme">
       <activity
           android:windowSoftInputMode="stateHidden"
           android:launchMode="singleTop"
           android:name=".main"
           android:label="Atlas SOS Now"
           android:screenOrientation="unspecified">
           <intent-filter>
              <action android:name="android.intent.action.MAIN" />
              <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
           
       </activity>
       <service android:name=".starter">
       </service>
       <receiver android:name=".starter$starter_BR">
       </receiver>
       <service android:name=".svc_intent">
       </service>
       <receiver android:name=".svc_intent$svc_intent_BR">
           
           <intent-filter> <action android:name="android.intent.action.START_SLIDETO_SOSSERVICE"/></intent-filter>
       </receiver>
       <activity
           android:windowSoftInputMode="stateHidden"
           android:launchMode="singleTop"
           android:name=".mainactivity"
           android:label="Atlas SOS Now"
           android:screenOrientation="unspecified">
           
           <intent-filter>
           <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
       </activity>
   </application>
</manifest>

We just tested and unfortunitly it did not work. Does the fact that this android:name=".mainactivity" is in lower case make any difference, as the sample we got done is
<activity android:name=".MainActivity">

Regards

J.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
It is not correct. The intent filter should be removed from the main activity.

The case is important. If the activity name must be MainActivity then you will need to create it with a small library.

Dont wish to bother you, how would I do that ?
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
It's because the case use in real world applications is very limited. If Erel constructed a car it would be like having I'm adding a wine cellar video cam to all fabrication line when only 1 person would really require it!
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
It's because the case use in real world applications is very limited. If Erel constructed a car it would be like having I'm adding a wine cellar video cam to all fabrication line when only 1 person would really require it!

Eh, I don't think so.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
B4A compiler lower cases the activity names. If there was a very good reason to change it then it would have been changed. Up until now (8 years) you are the only one who encountered an issue related to the activity case.

There is also a reasonable workaround.

Fair enough, if I create a library as you suggest will it not create the same issue ?

And just to understand this better, why does the compiler lower case the activity names
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
And just to understand this better, why does the compiler lower case the activity names
I made a mistake here. My policy is to avoid replying to feature requests: https://www.b4x.com/android/forum/threads/a-few-words-about-feature-requests.69064/
One of the reasons is that I cannot explain all the internal technical details.

Fair enough, if I create a library as you suggest will it not create the same issue ?
You can add any activity you like with a library. Start a new thread for further discussion.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Last edited:
Upvote 0
Top