Below is the code code of Android manifest
<application
android:name="com.example.m1.parsedemo.MainActivity" // this line show error
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>
</application>
and the main activity java file is
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Parse.enableLocalDatastore(this);
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("31e1ed2c6158fa0d01c3a5201a15e4af3f228a5b")
// if define
.clientKey("7d930e5059ba7ca44ce7083a6708b99eb70d9b4b")
.server("http://35.154.249.137:80/parse/")
.build()
);
ParseUser.enableRevocableSessionInBackground();
ParseObject gameScore = new ParseObject("Manish");
gameScore.put("score", 1337);
gameScore.put("playerName", "Manish");
gameScore.put("cheatMode", false);
gameScore.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if(e == null) {
Log.i("sucess","sucess");
} else {
Log.i("error",e.toString());
}
}
});
}
I am following this guideline -> parse
Removing
android:name=""
shows no error, but cant connect to the server and adding it, show error. I am stuck here cant connect to parse server.
And also please tell me is there any wrong code in main activity java file.
Thanx
You won't need this or you're referencing the wrong file in here:
android:name="com.example.m1.parsedemo.MainActivity" // this line show error
Which you already have:
<activity android:name=".MainActivity"
If you're trying to reference the Application class of your project, use a different name and create another class like calling it App, then:
android:name=".App"
In your AndroidManifest.xml application tag and these codes inside the onCreate() of the App class:
import com.parse.Parse;
import android.app.Application;
public class App extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("31e1ed2c6158fa0d01c3a5201a15e4af3f228a5b")
// if define
.clientKey("7d930e5059ba7ca44ce7083a6708b99eb70d9b4b")
.server("http://35.154.249.137:80/parse/")
.build()
);
}
}
Just like the documentation.
This should be name of your application class, not the activity class
<application
android:name="com.example.m1.parsedemo.MainActivity" // this line show error
</application
correct it with the application class which looks like this
public class App extends Application {
#Override
public void onCreate() {
super.onCreate();
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("YOUR_APP_ID")
// if defined
.clientKey("YOUR_CLIENT_KEY")
.server("http://localhost:1337/parse/")
.build()
);
}
}
Related
I need to close an activity when a button is clicked. Unfortunately, when button is clicked, the activity does disappear but is still in the background. User can still select it and it comes back to front. What I need is the activity completely gone/destroyed.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
finish();
}
});
}
#Override
protected void onDestroy() {
super.onDestroy();
}
}
I searched on SO on related questions, however, none of them help with closing the activity completely. I already tried adding return, adding another broadcast listener and passing command to call finish outside onCreate. So at this point, the question is - is this really possible or is this how Android works, you can call finish() but it is still in the background and user can re-launch it.
Here is xml file.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app1.test.myapplication">
<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>
</application>
</manifest>
EDIT: Adding android:excludeFromRecents="true" does not solve the issue. Here are steps to recreate this, if anyone thinks it is a duplicate or already solved, please try and post comment/answer, I will accept it.
Open Android Studio
Create empty activity project.
Add a button.
Add code in MainActivity's onCreate for button click listener.
Inside click listener, call finish.
Run the app and click button and see if the activity is still in background or not.
Just give it a try.
In you manifest.
<activity
android:excludeFromRecents="true"
android:name=".Activities.SplashActivity"
android:theme="#style/AppThemeSubActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Now in your java code.
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item_search:
// Intent intent = new Intent(MainActivity.this, SearchActivity.class);
// startActivity(intent);
finish();
System.exit(0);}
}
put the extra line System.exit(0); after calling finish it works for me.
You need to put this in your XML manifest:android:excludeFromRecents="true"
in your Activity TAG.
<activity
...
android:excludeFromRecents="true">
</activity>
You could try this
android:excludeFromRecents="true", Use it in your manifest.
plz try this to go back
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onBackPressed();
}
});
}
}
and this code to kill app process
moveTaskToBack(true);
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
I've been following the following tutorial to integrate my app with Facebook.
Facebook tutorial
I've followed everything on the tutorial, but I've been getting applicationId cannot be null in two cases, and it's really frustrating.
My FacebookActivity onCreate has the following, which is exactly the same as the tutorial:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
setContentView(R.layout.main_fb);
FragmentManager fm = getSupportFragmentManager();
fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);
FragmentTransaction transaction = fm.beginTransaction();
for(int i = 0; i < fragments.length; i++)
{
transaction.hide(fragments[i]);
}
transaction.commit();
}
However when I try to display the activity I get applicationId cannot be null, and the line LogCat points me to is: uiHelper.onCreate(savedInstanceState);
So then I tried commenting out that line, and the activity is displayed. However now when I click on the LoginButton, I get the same error but this time is points me to the applicationId field in the LoginButton class from facebook.
I already have the Id in my string values and my manifest like this:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/APP_ID"/>
I tried getting the Id using code, but nothing changed.
What exactly is causing all this?
TL;DR: you have to write your application's ID in your strings.xml and then reference (i.e. #strings/fb_app_id), because if you put it directly (as value) into AndroidManifest.xml it won't work.
you must define your applicationId in the AndroidManifest.xml
like this:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/app_id"/>
under <application android:label="#string/app_name".... tag
where app_id is a string within your strings.xml.
sample:
<application android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#android:style/Theme.NoTitleBar"
>
<activity android:name=".HelloFacebookSampleActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.LoginActivity"
android:theme="#android:style/Theme.Translucent.NoTitleBar"
android:label="#string/app_name" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/app_id"/>
</application>
** please note <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="#string/app_id"/> is within <application> tag
-- and in strings.xml
<string name="app_id">1389xxxxxxxx</string>
Since today the answer is not quite correct.
If someone didn't use this:
AppEventsLogger.activateApp(this);
Since last update you must do it or your app will crashed.
And you also should pass Application here not Context
https://developers.facebook.com/docs/android/getting-started
// Add this to the header of your file:
import com.facebook.FacebookSdk;
public class MyApplication extends Application {
// Updated your class body:
#Override
public void onCreate() {
super.onCreate();
// Initialize the SDK before executing any other operations,
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
}
}
The problem is that the id is being converted to integer:
https://code.google.com/p/android/issues/detail?id=78839
In my case the facebook_app_id was being set from the build.gradle file per flavor.
The solution was to wrap the id with ":
flavor.resValue "string", "facebook_app_id", "\"1111111111111\""
or if you would rather avoid escaping:
flavor.resValue "string", "facebook_app_id", '"1111111111111"'
This little code modification at the activity helped me.
#Override
protected void onCreate(Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(getApplication());
super.onCreate(savedInstanceState);
...................
...................
}
Actually you do not have to use flavor codes in gradle...
if you have number longer than 4 Bytes, you should this code in strings.xml
Note: Attention this quotation mark (")
<string name="facebook_app_id">"1111111111111"</string>
I trying to run a some tutorial samples for android live wall paper but always got this error
09-28 16:13:30.729: E/AndroidRuntime(408): java.lang.RuntimeException:
Unable to instantiate service
net.markguerra.android.glwallpaperexample.MyWallpaperService:
java.lang.ClassNotFoundException:
net.markguerra.android.glwallpaperexample.MyWallpaperService in loader
dalvik.system.PathClassLoader[/data/app/net.markguerra.android.glwallpaperexample-1.apk]
This is my manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.markguerra.android.glwallpaperexample"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name">
<service android:label="#string/service_label" android:name=".MyWallpaperService"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data android:name="android.service.wallpaper"
android:resource="#xml/myglwallpaper" />
</service>
</application>
<uses-sdk android:minSdkVersion="7" />
</manifest>
Wallpaper service i created
package net.markguerra.android.glwallpaperexample;
import net.rbgrn.android.glwallpaperservice.*;
// Original code provided by Robert Green
// http://www.rbgrn.net/content/354-glsurfaceview-adapted-3d-live-wallpapers
public class MyWallpaperService extends GLWallpaperService {
public MyWallpaperService() {
super();
}
public Engine onCreateEngine() {
MyEngine engine = new MyEngine();
return engine;
}
class MyEngine extends GLEngine {
MyRenderer renderer;
public MyEngine() {
super();
// handle prefs, other initialization
renderer = new MyRenderer();
setRenderer(renderer);
setRenderMode(RENDERMODE_CONTINUOUSLY);
}
public void onDestroy() {
super.onDestroy();
if (renderer != null) {
renderer.release();
}
renderer = null;
}
}
}
this is my projrct structure
I cant figure out whats going wrong in it, Whats the error ?
Any suggestions will be a great help for me
found some related questions on stack but not related to live wallpaper
You should include GLWallpaperService.jar in libs folder.
it must be libs not lib or am I mistaken? With libs you should see a small a on the folder like res or bin have...
in my app I am trying to add new screen. In my activity I've:
public void addItem(View v) {
Intent i = new Intent(SQLiteListActivity.this, add_screen.class);
startActivity(i);
}
In add_screen.java:
public class add_screen extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
In file add_screen.xml I've layout this screen. In file AndroidManifest.xml I added this next activity, especially:
<activity class=".Add_screen" android:name="ADD_ITEM" android:label="Add item">
</activity>
I am still getting an error message about "Application has been stopped." I am newbie in Android development, I tried to do this by some tutorial, I've everything by it, but I don't know why, I'm still getting the error message above...
Can you help me, please, with this problem? I've no idea, what could be wrong.
Try replacing the activity tag in your manifest with this instead:
<activity
android:name=".add_screen"
android:label="Add item"
>
<intent-filter>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
You shouldn't need the class attribute, I don't even know if that's recognized.
Edit: Try the above instead?
Im trying to do the backing up of my application's data into the Google Servers..
For doing this I've implemented a BackupAgent in my code and I included this in the Android Manifest file and "Meta-data" ( Got after registered my Application's package with the Android Backup Service)
When I run the application to do the backup this is not performing the backup.. Im using Nexus one device (connected to WIFI also) .
Could any one please let me know why it is not calling my BackupAgent's onBackup() method?
Am I missing some thing, to include in the Android manifest file or some where in the program?
The below is my manifest file..
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.simpledatabackup"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="#drawable/icon" android:label="#string/app_name"
android:backupAgent="MyBackupAgent"
android:debuggable="true">
<activity android:name=".SimpleDatabackup"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAIZn2ysSLR5wNbcq1uaoWQO0HuipMetQENVTsilw" />
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
and the source file is
public class SimpleDatabackup extends Activity {
private SharedPreferences myPrefs ; // Shared Preferences
BackupManager mBackupManager;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myPrefs = this.getSharedPreferences("shared_prefs", MODE_WORLD_READABLE);
SharedPreferences.Editor edit = myPrefs.edit();
edit.putString("firstname", "uday") ;
edit.putString("lastname", "kiran") ;
edit.commit() ;
mBackupManager.dataChanged();
}
}
My Backup Agent is some thing like this: I have not implemented the functionality inside is onBackup() and onRestore(). Once if it is called i will implement what ever i want..
public class MyBackupAgent extends BackupAgent {
#Override
public void onCreate() {
System.out.println("In MyBackuAgent's onCreate() method");
}
#Override
public void onBackup(ParcelFileDescriptor arg0, BackupDataOutput arg1,
ParcelFileDescriptor arg2) throws IOException {
System.out.println("In MyBackuAgent's onBackup()");
// TODO Auto-generated method stub
}
#Override
public void onRestore(BackupDataInput data, int appVersionCode,
ParcelFileDescriptor newState) throws IOException {
}
}
In the application tag in the manifest include
android:allowBackup="true"
android:restoreAnyVersion="true"
android:backupAgent="<package>.MyBackupAgent"
Please follow the "Testing your BackupAgent" section to invoke the backup instantly for testing.
BackupManagerService schedules the backup regularly in hour interval after the datachanged call to backupmanager. [grepcode]