second_fragment.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/f2_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/f2_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/f2_tv" />
<Button
android:id="@+id/f2_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="button"
android:text="@string/f2_bttn" />
Run Code Online (Sandbox Code Playgroud)
SecondFragment.java
public class SecondFragment extends Fragment {
FragmentInterface iface;
public interface FragmentInterface {
public void buttonPressed();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.second_fragment, container, false);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an …Run Code Online (Sandbox Code Playgroud) 我有一些带有源代码的字符串,例如
var newSource = @"
int a = 5;
int b = 10;
Console.WriteLine(a + b);";
Run Code Online (Sandbox Code Playgroud)
我尝试使用解析的代码创建BlockSyntax对象
var newTokens = SyntaxFactory.ParseTokens(newSource);
var newBody = SyntaxFactory.Block();
newBody = newBody.InsertTokensAfter(
newBody.OpenBraceToken, // or newBody.ChildTokens().First()
newTokens
);
Run Code Online (Sandbox Code Playgroud)
但是方法InsertTokenAfter方法引发System.InvalidOperationException'指定的项目不是列表的元素。'
据我了解,该方法无法在ChildTokens()中找到令牌,但是为什么会发生呢?
.NET Core 1.0.4
public void SetAlarm(Context context, int sec)
{
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
am.set(AlarmManager.RTC, System.currentTimeMillis()+1000*5 , pi);
i = new Intent(context, Alarm.class);
pi = PendingIntent.getBroadcast(context, 0, i, 0);
am.set(AlarmManager.RTC, System.currentTimeMillis()+1000*10 , pi);
}
Run Code Online (Sandbox Code Playgroud)
为什么onReceive只在10秒后工作一次?