How to show the "View chart" on main UI? - android

In my Android program, in the main activity (ReadLog), I will call another activity (History) like below.
Intent intent = new Intent();
intent.setClass(ReadLog.this, History.class);
startActivity(intent);
And in History activity, I will finish making a View called chart and start to show it like below.
View chart = ...;
setContentView(chart);
But now I hope to show it on main UI. So I add a View on main UI (below some buttons), and hope to show the chart inside of the main UI's View. How can I do it?

Related

startActivityOnResult() in recycler view onitemClick()

so I need to create a notes app, in which user opens and sees a RecyclerView-grid of notes. on clicking any note, it opens a new activity SecondActivity with 2 edit texts title and data.
On closing secondActivity, I want the user to see the title he had set in secondActivity on the grid he clicked on the main page.HOW?
After searching for a white, i got this startActivityForResult(). i understood its working, but it is not available in the adapter/holder, where my onitemclicklistener is present.
So how can i get to recieve this title? can I use the saveInstanceState bundle for this work?I also researched and observed that a child Acticvity's(SecondActivity) onSaveInstanceState is not called when the secondActivity is destroyed. so maybe that bundle thing would be a wrong path.In my OnBindHolder() function, i was using myholder.itemview.getContext().startActivity(...,...) for calling the secondActivity. I also tried passing the context for main Activity in adapter and using it for starting activity, but it still didn't show startActivityForResult() ...
UPDATE:
here are the java classes from my app(I have explained in detail about my problem in a comment in Main Activity.java):
MainActivity.java
Details.java
(Reycler View Files:)
RVadapter.java
RVholder.java
RVdata.java
RVfeeder.java
githubLink
You need to cast Context to Activity because it has startActivityForResult.
((Activity) context).startActivityForResult()
or
(((Activity) itemView.getContext()).startActivityForResult()

Show Indeterminate Indicator when loading another Activity

I'm trying to show my Indeterminate Progress Indicator When a certain Card is being tapped.
I declared the indicator in my onCreate as follows
mSlider = Slider.from(mCardScroller);
mIndeterminate = mSlider.startIndeterminate();
Then in my onclick I have the following
mIndeterminate.show();
intent = new Intent(getApplicationContext(), CaptureActivity.class);
startActivityForResult(intent, REQUEST_CODE);
I want to show the progress indicator while the QR-Scan activity is being loaded since this takes a few seconds.
However with this the indicator doesn't show up at all. Is there a way to make sure the indicator is being shown while the called upon activity is loading?
When I take out the startActivityForResult() it does start the indicator so I'm pretty sure it has something to do with the lifecycle of the activity, but I'm not sure how I should go about it in this case.
I guess you should put the slider in CaptureActivity instead.
Your slider is hidden. From my understanding, you start the progress bar in the activity which is moved to the background. The whole activity cannot be seen not only the progress bar.
Try moving these code into onCreate of CaptureActivity
mSlider = Slider.from(mCardScroller);
mIndeterminate = mSlider.startIndeterminate();
mIndeterminate.show();

StackOverflowError while navigating between activities of ActivityGroup

I am making an application with tabs. In that app same TabView is to be shown in multiple activities in hierarchy. For that i used ActivityGroup.
In my application i can navigate from first activity containing tab to its child activity and can come back to previous activity by pressing a button in child activity. While navigating between these two activities, i get StackOverflowError after few navigations.
I tried flag
Intent.FLAG_ACTIVITY_CLEAR_TOP
but it doesn't help.
I also tried
finish()
but it finishes whole ActivityGroup.
Then i tried method
finishActivityFromChild()
but still getting same error.
This is my code for moving from first activity containing tabs to its child-
intent = new Intent(context, ChildActivity.class);
View view = getLocalActivityManager().startActivity("activity2", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView();
setContentView(view);
finishActivityFromChild(getCurrentActivity(), 0);
And the same code i am using for coming back to parent activity on click of a button-
public void onClick(View arg0) {
intent = new Intent(context, ParentActivity.class);
View view = getLocalActivityManager().startActivity("activity1", intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView();
setContentView(view);
finishActivityFromChild(getCurrentActivity(), 0);
}
Now i have no idea what to do for this problem. Any help is appreciated.
Thanks in advance.
I think some code would help here. If I were you, I would try to plent printouts of functions called, to see what function is being called recuresively that might cause the stack overflow. (Some breakpoints might also do the trick)

Android - display a persistent view over all activities

I'd like to recreate a functionality similar to a Swing GlassPane to be able to display animations while the user uses the app "below" normally. I cannot simply create a separate layout and attach it to each activity since the animation state would be lost when switching activities.
Is there a way to keep a persistent view over all the activities of an Android application ?
Thanks.
No its not. Every Activity runs in its own thread and is by design supposed to be runnable standalone.
But you could persist the animation state into the DB or into sharedPreferences and start it over at the new activity.
What you could also do is to use a Spinner or another control instead of seperate activitys. Then you could have a persistent view.
why not think in a TabActivity?
hi! i do this before with a TabActivity, never with an only activity, always with many activitys wich i started, get theirs windows and setting as my TabActivity window´s decor view... i dont tested the code below, since is an idea, but maybe more lately (when i'll be on home) i'll write an example...
So, my idea...
a TabActivity is composed by a TabWidget and a FrameLayout where the activity´s windows is allocated.
the TabWidget can be any view, so, you can put the animated view here.
the most difficult thing is the fact that, if you start an activity from the TabActivity´s child, then the new activity will be on top of the TabActivity. In order to overrides this behavior the TabActivity must know when a nested activity wants to start another activity. When this happens the TabActivity must clear his decor view (with the old window activity) and put the decor view of new one. Something like this:
on the child activity, launch a new activity when we click on a button:
... on click listener...
((MyTabActivity)getParent()).createNewActivity("NewActivity", NewActivity.class);
now, we´re saying the TabActivity that it has to start a new activity, get the new activity decor view and put that view inside the TabActivity decor view... so, the createNewActivity will perform something like this:
public void createNewActivity(String activityId, Class<?> class1) {
Intent intent = new Intent( getIntent().getAction() ).setClass(MyTabActivity.this, class1);
Window wList = getLocalActivityManager().startActivity(activityId, intent);
getWindow().setContentView(wList.getDecorView());
}
hope you understand me.
i'll write an example later

Android Activity Group Implementation

i have multiple activities in my activityGroup under tabactvity.
I want to start the child actvity for result.
Intent i = new Intent(this, addstocks.class);
View view = stocksgroup.group.getLocalActivityManager()
.startActivity("show_city", i
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
// Again, replace the view
stocksgroup.group.replaceView(view);
this code basically taking me to the next activity. here i want to implement the actvity for result. hw can i do that?
It ts very late but just for reference a demo can be seen here: onActivityResult is not been invoked after the child activity calls finish()

Categories

Resources