startActivity crashes if I do not open the activity from another path - java

So I have 2 ways an activity can be opened. One is from the activity flow of:
Main > Tracks > Day > Topic > TrackSelect > TrackInfo
and the other is:
Main > MySchedule > TrackInfo
If I try to get TrackInfo to open up via the second path, it crashes the app.
However, If I go from the first path, then all the way back to the main, then through the second path, it works perfectly. Is there something weird going on?
AndroidManifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fayko.conference_app">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="Conference-App"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".mainSelection"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".topicScreen"/>
<activity
android:name=".myScheduleScreen" />
<activity android:name=".trackSelection" />
<activity android:name=".mainScreen" />
<activity android:name=".daySelection" />
<activity android:name=".trackInfoScreen" />
<activity android:name=".mapChoose" />
<activity android:name=".sponsorScreen" />
<activity android:name=".committeeScreen" />
<activity android:name=".welcomeScreen"></activity>
</application>
</manifest>
Code from TrackSelect > Track Info:
Intent intent = new Intent(trackSelection.this,trackInfoScreen.class);
startActivity(intent);
Code from MySchedule > TrackInfo:
Intent intent = new Intent(myScheduleScreen.this,trackInfoScreen.class);
startActivity(intent);
I appreciate any help you guys can give me.

It turns out that the issue I was having was due to some internal code. Even thought he stacktrace was saying things about socket lost for the debugger.

Related

Android App ist running on Device in USB-Debug-Mode but not after APK-Install

I am very new In Android Development and developed a "Time Stamp Clock - App" which reads NFC-Tags.
Everything fine, it is running on Device via USB-Debug-Mode without Errors as expected. When I build APK and install on the same Device, the installing is without errors, but after that, the open-button is grayed out and inactive and there is no desktop-icon to launch. In the APPS Overview it is displayed, but not able to open.
Can someone tell me, what can i do, to figure it out, what is going wrong there?
EDIT:
Manifest:
<?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.example.comidoszeiterfassung">
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk android:minSdkVersion="21"
android:targetSdkVersion="30"></uses-sdk>
<application
android:name=".myGLOBAL"
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.ComidosZeiterfassung"
tools:ignore="Instantiatable">
<activity
android:name=".ui.login.MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/Theme.ComidosZeiterfassung.NoActionBar"
android:exported="true">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<data android:mimeType="text/plain" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".ui.login.LoginActivity"
android:label="#string/app_name"
android:exported="true">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
</application>
</manifest>
It is a simple structure in the app. LoginActivity as Start-Activity and a TabbedActivity for the NFC-Stuff.

Unable to remove activity from stack,

I am starting an activity from service. ,
In this i set two flags one is
Intent.FLAG_ACTIVITY_NEW_TASK
because i am running activity from service.its new
Intent.FLAG_ACTIVITY_NO_HISTORY is set to new activity is not kept in the history stack. As soon as the user navigates away from it, the activity is finished.
Here is the code which i call from service to open activity
public static void open(Context context){
Intent intent=new Intent(context,PopupActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NO_HISTORY);
context.startActivity(intent);
}
and i have cross button in my activity to destroy activity , when i press cross button activity should remove from stack,but it remain in stack and when press home button to view it, activity recreated in stack.for example "oncreate" is again called
here is my code.
#OnClick(R.id.flClose) void closeWindow(){
finish();
}
Here is my manifest activity code.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackagename">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name=".app.MyApplication"
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.NoActionBar">
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DashboardActivity"
android:screenOrientation="portrait" />
<activity
android:name=".SearchUserActivity"
android:screenOrientation="portrait" />
<activity
android:name=".TermsPolicyActivity"
android:screenOrientation="portrait" />
<activity
android:name=".UserDetailActivity"
android:screenOrientation="portrait" />
<activity
android:name=".DocumentViewerActivity"
android:screenOrientation="portrait" />
<activity
android:noHistory="true"
android:name=".PopupEndActivity"
android:configChanges="orientation|keyboardHidden"
android:theme="#style/Theme.AppCompat.Transparent.NoActionBar" />
<activity
android:name=".BlockActivity"
android:theme="#style/Theme.AppCompat.Transparent.NoActionBar" />
<activity
android:name=".BlockSettingsActivity"
android:theme="#style/AppTheme.NoActionBar"
android:configChanges="orientation|keyboardHidden"
/>
<service
android:name=".service.SyncDataService"
android:enabled="true"
android:exported="false" />
</application>
</manifest>
Try using finishAffinity() instead of finish()
Add the following flags instead of setflags to open activity
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
And on close button call the function below
private void endTask() {
if (Build.VERSION.SDK_INT >= 21) {
finishAndRemoveTask();
} else {
finish();
}
}
You can get this behaviour by setting the android:noHistory attribute to "true" in the relevant entries in your AndroidManifest.xml file.
For example:
<activity
android:name=".YourActivity"
android:noHistory="true" />
I solved My problem by Adding flag Intent.FLAG_ACTIVITY_NEW_DOCUMENT This flag is used to open a document into a new task rooted at the activity launched
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
In manifest i have noHistory
android:noHistory="true"

Launcher activity not starting first

The title explains it pretty much, here is the manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="eu.craym.vulcrum.firstgametnb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".StartingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="eu.craym.vulcrum.STARTINGPOINT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Yet whenever I run this application, the StartingPoint classed is called first:
[2013-03-09 18:36:40 - FirstGameTNB] Starting activity eu.craym.vulcrum.firstgametnb.StartingPoint on device emulator-5554
Why is this happening? I thought the MAIN and LAUNCHER were supposed to make it so the Splash class gets called first, but this never happens. Note that when I delete the StartingPoint activity, it goes to Splash.
You're right. You may try a clean on your project.
android.intent.action.MAIN: Start as a main entry point, does not
expect to receive data.
Source

Activity permission Denial

I've encountered a strange permission denial in my Android app, here is my manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest package="test.mymax"
android:versionCode="1"
android:versionName="1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/splash"
android:label="#string/app_name" android:debuggable="true">
<activity
android:name=".Test_mymaxActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="A_Info"></activity>
<activity android:name="A_Info_Refresh"></activity>
<activity android:name="_TagConnector"></activity>
<activity android:name="_SQLconnect"></activity>
<activity android:name="_TagReader"></activity>
<activity android:name="_TagReader_Refresh"></activity>
<activity android:name="Test_mymaxActivity"></activity>
</application>
</manifest>
the error i get is:
ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=test.mymax/.Test_mymaxActivity } from null (pid=17572, uid=2000) requires null
Please help I have no idea on what's wrong
You declared your Test_mymaxActivity twice. Once here
<activity
android:name=".Test_mymaxActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and below a second time
<activity android:name="Test_mymaxActivity"></activity>
Can you post the Intent/Code you are using that is requesting the permission? Or is this immediately on launching your activity?
Are you sure you declared all the permission needed for your code (using internet, detect phone state, etc)
Here's the documentation : Manifest permission - Android dev

the application on android cant run

why??
[2011-08-26 14:57:48 - Front] ActivityManager: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=mpos.gui.ask/.Front } from null (pid=5918, uid=2000) requires null
my manifest
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mpos.gui.ask" android:versionCode="1" android:versionName="1.0">
<application android:debuggable="true" android:icon="#drawable/icon"
android:label="#string/app_name">
<activity android:name=".Front" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Login"></activity>
<activity android:name="FtpList"></activity>
<activity android:name="LoginMpos"></activity>
<activity android:name="MenuMpos"></activity>
<activity android:name="PilihCabang"></activity>
<activity android:name="FormTransaksi"></activity>
<activity android:name="SdhTrans"></activity>
<activity android:name="BuatTransaksi"></activity>
<activity android:name="LihatTrans"></activity>
<activity android:name="CekStok"></activity>
</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
</manifest
i'm pasive english :D
anyone can help
thanks be4
Are you accessing network status in your application too? If so I think you need to include permission for this too in your manifest.
In my case with flutter, I had a similar error that was solved by adding android:exported="true" to the main activity, so in your case it seems to be here
<activity android:name=".Front" android:label="#string/app_name" android:exported="true">

Categories