I am making chat app and want to share app via Intent . There are not many solution to the problem please help. here is my code but it is throwing error in start Activity
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
#SuppressLint("NonConstantResourceId")
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem menuItem) {
switch (menuItem.getItemId()){
case R.id.share :
ApplicationInfo api = getApplicationContext().getApplicationInfo();
String apkPatch = api.sourceDir;
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("application/vnd.android.package-archive");
intent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(new File(apkPatch)));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(Intent.createChooser(intent, "ShareVia"));
Toast.makeText(NavigationActivity.this, "shareVia", Toast.LENGTH_SHORT).show();
case R.id.aboutus :
Toast.makeText(getApplicationContext(), "aboutUs", Toast.LENGTH_SHORT).show();
}
return true;
}
});
and this is the error in Run screen
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.chatbox, PID: 19897
android.os.FileUriExposedException: file:///data/app/com.example.chatbox-7bck8l1ys2PwFlDmiMFq2w%3D%3D/base.apk exposed beyond app through ClipData.Item.getUri()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:2083)
at android.net.Uri.checkFileUriExposed(Uri.java:2388)
at android.content.ClipData.prepareToLeaveProcess(ClipData.java:977)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10809)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10815)
at android.content.Intent.prepareToLeaveProcess(Intent.java:10794)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1710)
at android.app.Activity.startActivityForResult(Activity.java:5331)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:675)
at android.app.Activity.startActivityForResult(Activity.java:5262)
at androidx.fragment.app.FragmentActivity.startActivityForResult(FragmentActivity.java:662)
at android.app.Activity.startActivity(Activity.java:5660)
at android.app.Activity.startActivity(Activity.java:5628)
at com.example.chatbox.NavigationActivity$1.onNavigationItemSelected(NavigationActivity.java:121)
at com.google.android.material.navigation.NavigationView$1.onMenuItemSelected(NavigationView.java:170)
at androidx.appcompat.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:834)
at androidx.appcompat.view.menu.SubMenuBuilder.dispatchMenuItemSelected(SubMenuBuilder.java:91)
at androidx.appcompat.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:158)
at androidx.appcompat.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:985)
at com.google.android.material.internal.NavigationMenuPresenter$1.onClick(NavigationMenuPresenter.java:352)
at android.view.View.performClick(View.java:7257)
at android.view.View.performClickInternal(View.java:7213)
at android.view.View.access$3800(View.java:828)
at android.view.View$PerformClick.run(View.java:27921)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7830)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1040)
I/Process: Sending signal. PID: 19897 SIG: 9
The problem is that for new APIs, a file URI scheme is different than its scheme of old APIs. So creating a file using new File(apkPatch) will raise this exception for newer APIs.
So, you can pass the String to Uri.parse, not the File for solving this instead of using Uri.fromFile
So replace the below line of code:
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(apkPatch)));
With:
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(apkPatch));
I have tried your solutions and it works pretty well but the apk file name is base.apk but i want my app name there(Chat Box) instead of base
Now to change the apk file name add below to the intent
intent.putExtra(Intent.EXTRA_SUBJECT, "Chat Box.apk");
Related
So, I have to get GPS data from file MetaData. "No problem", I said, "This will only take an hour or two". Six hour later, here I am searching through all Android Documentation and Stack exchange questions I can yet I still cant get it to work.
My Code is straight forward:
I am using a ACTION_PICK to select a video (ACTION_OPEN_DOCUMENT Doesn't work either).
I Have already requested the following permissions and added to the Manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION" />
Below is code from the button listener
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK , MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
//intent.setType("video/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
startActivityForResult(Intent.createChooser(intent,"Select A Video"),REQUEST_VIDEO_CONTENT);
}
});
And From the OnActivityResult:
protected void onActivityResult(int requestCode, int resultCode, Intent vIntent) {
super.onActivityResult(requestCode, resultCode, vIntent);
if ((requestCode == REQUEST_VIDEO_CAPTURE || requestCode == REQUEST_VIDEO_CONTENT) && resultCode == RESULT_OK) {
//Attempt to get Content Data
vIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
vIntent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
Uri vUri = vIntent.getData();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
vUri = MediaStore.setRequireOriginal(vUri);
}
try {
InputStream vIS = getContentResolver().openInputStream(vUri);
ExifInterface vExif = new ExifInterface(vIS);
} catch (SecurityException | IOException e) {
e.printStackTrace();
}
And finally, the lovely SecurityException:
W/System.err: java.lang.SecurityException: Permission Denial: reading com.google.android.apps.photos.contentprovider.impl.MediaContentProvider uri content://com.google.android.apps.photos.contentprovider/0/2/content%3A%2F%2Fmedia%2Fexternal%2Fvideo%2Fmedia%2F198668/ORIGINAL/NONE/video%2Fmp4/328149382?requireOriginal=1 from pid=6190, uid=10146 requires the provider be exported, or grantUriPermission()
W/System.err: at android.os.Parcel.createException(Parcel.java:2071)
at android.os.Parcel.readException(Parcel.java:2039)
W/System.err: at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:151)
W/System.err: at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:705)
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1710)
W/System.err: at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1526)
W/System.err: at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1345)
at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1293)
W/System.err: at com.equinox.openeyes.VideoSubmission.onActivityResult(VideoSubmission.java:117)
at android.app.Activity.dispatchActivityResult(Activity.java:8147)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4883)
W/System.err: at android.app.ActivityThread.handleSendResult(ActivityThread.java:4931)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
W/System.err: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2022)
W/System.err: at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:235)
W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7441)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
I get that the Error is saying the provider needs to be exported, or grantUriPermission which sounds like an easy fix, except I cannot find a way to implement what they ask. All the places I have looked have suggested adding flags.. as you can see it didnt work.
Please Help :-(
I am trying to open a file from my emulator's internal storage (was trying to put it in sdcard but it put to internal storage?). I have the user choose a file, then pass that file's Uri (note the case) to a text editing activity via intent. In this activity, I've tried a few things. My current code looks like this (excuse the madness, I've been trying a LOT of things):
try {
Intent intent = getIntent();
File file;
Uri uri = Parcels.unwrap(intent.getParcelableExtra("uri"));
URI newUri = new URI("file://"+uri.toString());
Log.d("uri", uri.toString());
Log.d("newUri", newUri.toString());
file = new File(newUri);
if (intent != null) {
Log.d("uriPath", uri.toString());
if (uri != null) {
file = new File(uri.getPath());
String text = readTextFile(file);
if (text != null) {
Log.d("in if text not null", text);
mEditText.setText(text);
}
// mEditText.setText(readTextFile(file));
}
}
}
catch(URISyntaxException e) { e.printStackTrace(); }
I've tried a LOT of things, with no success. I'm either getting file not found (as it's not prefixing the file with anything, just trying to load "document/primary%3Aindex.html"), or other exceptions, currently:
06-06 05:43:18.826 10794-10794/net.a40two.pext E/AndroidRuntime: FATAL EXCEPTION: main
Process: net.a40two.pext, PID: 10794
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.a40two.pext/net.a40two.pext.ui.EditorActivity}: java.lang.IllegalArgumentException: Found authority in URI: file://content://com.android.externalstorage.documents/document/primary%3Aindex.html
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalArgumentException: Found authority in URI: file://content://com.android.externalstorage.documents/document/primary%3Aindex.html
at java.io.File.checkURI(File.java:230)
at java.io.File.<init>(File.java:175)
at net.a40two.pext.ui.EditorActivity.onCreate(EditorActivity.java:67)
at android.app.Activity.performCreate(Activity.java:6237)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
This happens even without the file:// concatenation. Most anything I can find online is either incredibly old, doesn't work, or both. Any help is sincerely appreciated.
The code in my main activity where I'm getting this URI is straight from developers.android.com:
public void onActivityResult(int requestCode, int resultCode,
Intent resultData) {
// The ACTION_OPEN_DOCUMENT intent was sent with the request code
// READ_REQUEST_CODE. If the request code seen here doesn't match, it's the
// response to some other intent, and the code below shouldn't run at all.
if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
// The document selected by the user won't be returned in the intent.
// Instead, a URI to that document will be contained in the return intent
// provided to this method as a parameter.
// Pull that URI using resultData.getData().
Uri uri = null;
if (resultData != null) {
uri = resultData.getData();
Log.i("onActivityResult", "Uri: " + uri.toString());
Intent intent = new Intent(MainActivity.this, EditorActivity.class);
intent.putExtra("uri", Parcels.wrap(uri));
startActivity(intent);
finish();
}
}
}
I am using chrome tabs to view URLs from my android app, but i got some crashes with this stacktrace
Fatal Exception: java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW dat=http://www.ikea.com/... cmp=com.alibaba.intl.android.apps.poseidon/com.alibaba.android.intl.weex.activity.WeexPageActivity (has extras) } from ProcessRecord{2fec948 29204:com.myapp/u0a71} (pid=29204, uid=10071) not exported from uid 10219
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:3131)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1540)
at android.app.Activity.startActivityForResult(Activity.java:4283)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
at android.app.Activity.startActivity(Activity.java:4563)
at android.support.v4.content.ContextCompatJellybean.startActivity(ContextCompatJellybean.java:34)
at android.support.v4.content.ContextCompat.startActivity(ContextCompat.java:151)
at android.support.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:262)
at com.myapp.chromeCustomTabs.CustomTabActivityHelper.openCustomTab(CustomTabActivityHelper.java:34)
at com.myapp.ProductSpecsActivity.goToStoreWebPage(ProductSpecsActivity.java:253)
at com.myapp.ProductSpecsActivity.goSeeDescription(ProductSpecsActivity.java:190)
at com.myapp.ProductSpecsActivity_ViewBinding$4.doClick(ProductSpecsActivity_ViewBinding.java:80)
at butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
at android.view.View.performClick(View.java:5697)
at android.widget.TextView.performClick(TextView.java:10826)
at android.view.View$PerformClick.run(View.java:22526)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7225)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
So, can anyone helps me to figure out what is the problem ? BTW it only happens on some devices and i can't reproduce it while testing on my own devices.
and here is the method that causes the issue
public static void openCustomTab(Activity activity,
Uri uri) {
// create an intent builder
CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
// Begin customizing
// set toolbar colors
intentBuilder.setToolbarColor(ContextCompat.getColor(activity, R.color.colorPrimary));
intentBuilder.setSecondaryToolbarColor(ContextCompat.getColor(activity, R.color.colorPrimaryDark));
// set start and exit animations
intentBuilder.setStartAnimations(activity, R.anim.slide_in_right, R.anim.slide_in_right);
intentBuilder.setExitAnimations(activity, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
// build custom tabs intent
CustomTabsIntent customTabsIntent = intentBuilder.build();
// launch the url
customTabsIntent.launchUrl(activity, uri);
}
activity the launches the CustomTab in manifest
<activity
android:name=".ui.activities.productspecs.ProductSpecsActivity"
android:configChanges="orientation|screenSize"
android:label="#string/title_activity_product_specs"
android:theme="#style/AppTheme.Base"
android:windowSoftInputMode="adjustResize" />
That was the issue, https://github.com/alibaba/weex/issues/2139 it is related to Alibaba's app bug conflicts with a CustomTabs
I have the following error in my app:
Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://m.fretebras.com.br/fretes }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1632)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424)
at android.app.Activity.startActivityForResult(Activity.java:3468)
at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
at android.app.Activity.startActivityForResult(Activity.java:3429)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
at android.app.Activity.startActivity(Activity.java:3671)
at android.app.Activity.startActivity(Activity.java:3639)
at br.lgfelicio.atividades.Checkin.acaoBotao(Checkin.java:773)
at br.lgfelicio.atividades.Checkin$12.onClick(Checkin.java:312)
at android.view.View.performClick(View.java:4461)
at android.view.View$PerformClick.run(View.java:18543)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5118)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
at dalvik.system.NativeStart.main(NativeStart.java)
Code with error:
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.fretebras.com.br/fretes"));
startActivity(i);
The error occurs in versions 6.0.1 android, I have no idea why it's happening, I believe that by passing the url to Intent is all right. Can someone help me?
Seems like no browser installed on your phone. Please verify and to avoid crash use below code.
try {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://m.fretebras.com.br/fretes"));
startActivity(i);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
Note - This code will just ignore your crash, if no browser found.
I'm performing file viewing operation as follows:
private void openFile(File file, String format) {
try {
if (file.exists()) {
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
String mimeType = "*/*";
if (format.length() > 0) {
mimeType = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(format);
if (mimeType == null)
mimeType = "*/*";
} else
mimeType = "*/*";
intent.setDataAndType(path, mimeType);
try {
startActivity(intent);
} catch (Exception e) {
Toast.makeText(LoginSuccessActivity.this,
constants.Error_NoCompatibleApp, Toast.LENGTH_SHORT)
.show();
e.printStackTrace();
}
} else {
Toast.makeText(LoginSuccessActivity.this,
constants.Error_DocNotFound, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
This is working fine, as I get app chooser pop-up for the filetypes which has multiple apps related to it(for eg. kingsoft office and polaris office for word file) OR directly file is opened for the filetypes which has only one app related to it(HTMLViewer for html file).
What I don't understand is my main activity is getting destroyed in few moments after calling file viewer activity. I've checked this by placing logs in onPause(), onStop() and onDestroy(). So, after file viewing is done, when I press back key, instead of taking back to app, it navigated to main menu.
I tried with startActivityForResult(intent, 1); instead of startActivity(intent); hoping that it'll preserve my main activity as it'll be waiting for result, but to no avail.
Please note that I've added android:configChanges="orientation|screenSize" in manifest file and
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
in java file.
Am I doing anything wrong?
Any help appreciated.
Sometimes, mind you, "Sometimes", I get follwing messages on log:
file:// Uri exposed through Intent.getData()
java.lang.Throwable: file:// Uri exposed through Intent.getData()
at android.os.StrictMode.onFileUriExposed(StrictMode.java:1597)
at android.net.Uri.checkFileUriExposed(Uri.java:2338)
at android.content.Intent.prepareToLeaveProcess(Intent.java:7194)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1418)
at android.app.Activity.startActivityForResult(Activity.java:3423)
at android.app.Activity.startActivityForResult(Activity.java:3384)
at android.app.Activity.startActivity(Activity.java:3626)
at android.app.Activity.startActivity(Activity.java:3594)
at com.android.internal.app.ResolverActivity.onIntentSelected(ResolverActivity.java:407)
at com.android.internal.app.ResolverActivity.startSelected(ResolverActivity.java:299)
at com.android.internal.app.ResolverActivity.onButtonClick(ResolverActivity.java:289)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3809)
at android.view.View.performClick(View.java:4424)
at android.view.View$PerformClick.run(View.java:18383)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4998)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
at dalvik.system.NativeStart.main(Native Method)
Add these lines to your Intent and try to Start Activity,
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType(Your_MimeType);
I m using this code in my App
String MimeType = URLConnection.guessContentTypeFromName(myFile.getAbsolutePath());
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType(MimeType);
Uri uri_path = Uri.fromFile(myFile);
intent.setDataAndType(uri_path, MimeType);
try
{
_context.startActivity(intent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(_context,"Activity Not Found..", Toast.LENGTH_SHORT).show();
}
Refer this link also for better understanding
Hope it will help you.
Activity can get destroyed any time. If someone has some data to retain one can do as follows:
class MyActivity {
private String mMyString;
public void onSaveInstanceState(Bundle b) {
b.putString("MYDATA", mMyString);
super.onSaveInstanceState(b);
}
public void onCreate(Bundle savedState) {
super.onCreate(savedState)
if(savedState != null) {
mMyString = savedState.getString("MYDATA");
}
}
You can this way create your own subclass private static class State implements Serializable and save it in onSaveInstanceState()