sometimes the application does run but its very slow and messes up. I attached the main activity and the manifest, I think it is one of those that is making the application mess up. Sometimes it gives me this error : Session 'MainActivity': error.
Any help would be greatly appreciated.
Thank you.
Main Activity
import Graphics.MyGLSurfaceView;
import gameInfo.GameDatabase;
public class MainActivity extends ActionBarActivity {
//Runs before the application is created
private Button mCampaignButton;
private Context context = this;
private GLSurfaceView mGLView;
//When the application is created
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//New thread to perform database creation / filling
Runnable runnable = new Runnable(){
public void run(){
//Instantiate a GameDatabase object (this activity)
final GameDatabase gDB = new GameDatabase(context);
gDB.fillGameDatabase();
}
};
Thread myThread = new Thread(runnable);
myThread.start();
mGLView = new MyGLSurfaceView(this);
setContentView(mGLView);
//Keeps screen on so it doesn't fall asleep
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
//Finding button by button id after application is created
mCampaignButton = (Button)findViewById(R.id.campaignButtonID);
//Checks if the campaign button is clicked
mCampaignButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Intent to go from main activity to campaign Level Select Activity
final Intent intent = new Intent(MainActivity.this, CampaignSelectLevel.class);
startActivity(intent);
}
});
}
}
Android Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tekvision.codedecrypter">
<!-- Tell the system this app requires OpenGL ES 2.0. -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<supports-gl-texture android:name="GL_OES_compressed_ETC1_RGB8_texture" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
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=".CampaignSelectLevel"
android:label="#string/title_activity_campaign_select_level" >
</activity>
<!-- Anagrams.Modern Era is to get java class from different package-->
<activity android:name="anagrams.Modern_Era"
android:label="Modern_Era">
</activity>
</application>
Make sure that you are declaring all the permissions in manifest file required by your application i.e.
<uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE"/>
for more details check this: uses-permission
Related
I am working on a simple project which is responsible to launch and quit another installed application (let's call it "abc") on the tablet.
The other application ("abc") is already installed in tablet. I can launch it using Intent. But need to find a way to quit it as well.
Here is the template of my mainActivity.java file.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final LinearLayout parent = findViewById(R.id.parent);
Button launchApp = (Button) findViewById(R.id.button);
Button quitApp = (Button) findViewById(R.id.button2);
launchApp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.abc");
if (launchIntent != null) {
startActivity(launchIntent);
} else {
Toast.makeText(MainActivity.this, "There is no package available in android", Toast.LENGTH_LONG).show();
}
}
});
quitApp.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Add code to close the installed app on tablet ("com.abc")
}
});
}
}
This is also my activitymanifest.xml file:
<?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.launcherQuitterApp">
<!--uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" /!-->
<!--uses-permission android:name="android.permission.com.abc"
tools:ignore="ProtectedPermissions" /!-->
<uses-permission android:name="android.permission..com.abc"></uses-permission>
<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/Theme.LauncherQuitterApp">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<queries>
<package android:name="com.abc"/>
</queries>
</manifest>
I have tried the suggestions in the following threads, but none of them worked for me:
How to get PID from package name?
Followed the suggestion of this thread, but when I tried to list all running applications, it only reported the running application (the one through which i want to close the other application)
Android Permission Denial: forceStopPackage()
I am trying to create a pop-up window/overlay in Android Studio with 2 activities. When a certain button (the green plus button in the first picture below) is pressed, it will start a second activity at a smaller size with a different layout (.xml) file. When the second activity is declared in the AndroidManifest.xml, it uses a custom theme I have created to make the first activity appear under it, however, it is not working properly.
Here are pictures of both activites:
First Activity -
Second Activity -
Here is the code:
MainActivity -
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
Util.initScreenRes(this); // initializes screen resolution for later pop-up window sizing
}
public void ibAddOnClick(View view){
startActivity(new Intent(MainActivity.this, AddPopUpActivity.class));
}
}
AddPopUpActivity -
public class AddPopUpActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_popup_activity);
getWindow().setLayout((int) (Util.screenRes.x * 0.8), (int) (Util.screenRes.y * 0.5));
}
}
Util -
public class Util {
public static Point screenRes;
public static void initScreenRes(Activity a){
final DisplayMetrics dm = new DisplayMetrics();
a.getWindowManager().getDefaultDisplay().getMetrics(dm);
screenRes = new Point(dm.widthPixels, dm.heightPixels);
}
}
Lastly, here is the AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="App.ProgressTracker">
<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/Theme.ProgressTracker">
<activity
android:name="App.FrontEnd.MainActivity"
android:label="#string/app_name"
android:theme="#style/Theme.ProgressTracker.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="App.FrontEnd.AddPopUpActivity"
android:label="ProgressTracker"
android:theme="#style/Theme.ProgressTracker.PopUp">
</activity>
</application>
</manifest>
For reference, I have used this tutorial on YouTube for the way I went about this:
https://www.youtube.com/watch?v=fn5OlqQuOCk&ab_channel=FilipVujovic
I'd appreciate any help on this. Thank you in advance!
In the AndroidManifest.xml set the theme of the pop up activity to
android:theme="#android:style/Theme.Dialog"
My manifest.xml raises error for ".RoleActivity". But If I replace my ".roleActivity" with others for checking, they all are okay. Here is my manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zobaed.androidlogin" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".RoleActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".DoctorLoginActivity">
</activity>
<activity android:name=".PatientLoginActivity">
</activity>
</application>
</manifest>
Here is my RoleActivity. Tried to write switch case here.
public class RoleActivity extends AppCompatActivity {
private Button btnPatient;
private Button btnDoctor;
private Button btnGuest;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.log_in_role);
btnPatient = (Button) findViewById(R.id.btpatient);
btnDoctor = (Button) findViewById(R.id.btdoctor);
btnGuest = (Button) findViewById(R.id.btguest);
btnPatient.setOnClickListener((View.OnClickListener) this);
btnDoctor.setOnClickListener((View.OnClickListener) this);
btnGuest.setOnClickListener((View.OnClickListener) this);
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btdoctor: {
Intent i = new Intent(getApplicationContext(), DoctorLoginActivity.class);
startActivity(i);
break;
}
case R.id.btpatient: {
Intent i = new Intent(getApplicationContext(), PatientLoginActivity.class);
startActivity(i);
break;
}
}
}
}
implement onClickListner in RoleActivity class and change code to
btnPatient.setOnClickListener( this);
btnDoctor.setOnClickListener(this);
btnGuest.setOnClickListener(this);
Your activity is not implementing View.OnClickListener. Unless you implement View.OnClickListener on your activity you cannot cast the activity as an OnClickListener. That is why you are getting error, probably a ClassCastException
btnPatient.setOnClickListener((View.OnClickListener) this);
btnDoctor.setOnClickListener((View.OnClickListener) this);
btnGuest.setOnClickListener((View.OnClickListener) this);
implement View.OnClickListener on your activity. Change
public class RoleActivity extends AppCompatActivity
to
public class RoleActivity extends AppCompatActivity implements View.OnClickListener
and then you can remove that casting
btnPatient.setOnClickListener(this);
btnDoctor.setOnClickListener(this);
btnGuest.setOnClickListener(this);
if you are not implemeting View.OnClickListener on your activity you can add the click listener as an anonymous inner class to handle clicks on views
Unfortunately, app has stopped. The purpose of the app is to display a web page when it is launched. I have researched this problem, and tried changing code in the manifest file. I have been unsuccessful at eliminating this message.
MainActivity.java
package com.example.testb1;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.net.Uri;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState)
{
Intent getmobilepages = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.mcohio.org/government/auditor/mobile_app/home.cfm");
getmobilepages.setData(uri);
startActivity(getmobilepages);
}
}
testb1 Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testb1"
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="com.example.testb1.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.getmobilepages" />
</intent-filter>
</activity>
</application>
</manifest>
Edit: I tried running your code and was completely wrong. You are just missing the line:
super.onCreate(savedInstanceState);
At the start of your oncreate method. Add that in and it should compile just fine.
Make sure to post your logcat in the future, the error is identified clearly there.
You have not called super you will get SuperNotCalled Exception. You need to set you layout. Better to start another activity on button click.
Add internet permission in manifest
<uses-permission android:name="android.permission.INTERNET"/>
MainActivty
public class MainActivity extends Activity {
Button b;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// call super
setContentView(R.layout.activity_main);
// set your layout
b = (Button) findViewById(R.id.button1);
//get button id
b.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// do something
Intent getmobilepages = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("http://www.mcohio.org/government/auditor/mobile_app/home.cfm");
getmobilepages.setData(uri);
startActivity(getmobilepages);
}
});
}
}
I am a beginner of Android and i need a bit hints and help. I am using following code
public class WifiHotSpotActivity extends Activity {
private Button adnew = null;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
adnew = (Button) findViewById(R.id.addNewBtn);
adnew.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
Intent myIntent = new Intent(v.getContext(), addNew.class);
startActivityForResult(myIntent, 0);
}
});
}
The error i am receiving is
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.kahaf.wifiHotSpot/com.kahaf.wifiHotSpot.addNew}; have you declared this activity in your AndroidManifest.xml?
if anyone can tell me what is the problem.
You should define your activity in the manifest file. Here's an example how your manifest should look after the addition of that activity:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.foo.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="7" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
>
<activity
android:label="#string/app_name"
android:name=".FooActivity"
android:configChanges="keyboardHidden">"
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".YourActivityNameHere"
android:label="#string/app_name"
>
</activity>
<activity
android:name=".AnotherActivity"
android:label="#string/app_name"
>
</activity>
</application>
</manifest>
put this to AndroidManifest.xml
<activity android:name=".WifiHotSpotActivity"/>
It looks like you've not defined the Activity Element in the manifest xml for WifiHotSpotActivity. Without this you will be unable to launch this activity.
go to manifest the application tag.. add activity "addNew" which you are calling in button click..